lib/yaks-html/rspec.rb in yaks-html-0.11.0 vs lib/yaks-html/rspec.rb in yaks-html-0.12.0

- old
+ new

@@ -33,15 +33,15 @@ def submit! find('input[type="submit"]').click end def within_form(name, &block) - within(all("form[@name=\"#{name}\"]").first, &block) + within(find_form(name), &block) end def submit_form(name, &block) - within(all("form[@name=\"#{name}\"]").first) do + within(find_form(name)) do yield block submit! end end @@ -49,9 +49,23 @@ visit current_path end def env YaksHTML::RACK_ENV + end + + private + + def find_form(name) + forms = all("form[@name=\"#{name}\"]") + + if forms.empty? + fname = "/tmp/page-#{rand(999999999999999)}.html" + File.write(fname, page.body) + raise "No form found with name #{name}. Page saved as #{fname}" + end + + forms.first end end end RSpec.configure do |config|