lib/generators/cucumber/install/templates/step_definitions/web_steps.rb.erb in cucumber-rails-1.0.2 vs lib/generators/cucumber/install/templates/step_definitions/web_steps.rb.erb in cucumber-rails-1.0.3

- old
+ new

@@ -52,11 +52,11 @@ # | Account Number | 5002 | # | Expiry date | 2009-11-01 | # | Note | Nice guy | # | Wants Email? | | # -# TODO: Add support for checkbox, select og option +# TODO: Add support for checkbox, select or option # based on naming conventions. # When /^(?:|I )fill in the following:$/ do |fields| fields.rows_hash.each do |name, value| When %{I fill in "#{name}" with "#{value}"} @@ -138,9 +138,52 @@ if field_value.respond_to? :should_not field_value.should_not =~ /#{value}/ else assert_no_match(/#{value}/, field_value) end + end +end + +Then /^the "([^"]*)" field should have the error "([^"]*)"$/ do |field, error_message| + element = find_field(field) + classes = element.find(:xpath, '..')[:class].split(' ') + + form_for_input = element.find(:xpath, 'ancestor::form[1]') + using_formtastic = form_for_input[:class].include?('formtastic') + error_class = using_formtastic ? 'error' : 'field_with_errors' + + if classes.respond_to? :should + classes.should include(error_class) + else + assert classes.include?(error_class) + end + + if page.respond_to?(:should) + if using_formtastic + error_paragraph = element.find(:xpath, '../*[@class="inline-errors"][1]') + error_paragraph.should have_content(error_message) + else + page.should have_content("#{field.titlecase} #{error_message}") + end + else + if using_formtastic + error_paragraph = element.find(:xpath, '../*[@class="inline-errors"][1]') + assert error_paragraph.has_content?(error_message) + else + assert page.has_content?("#{field.titlecase} #{error_message}") + end + end +end + +Then /^the "([^"]*)" field should have no error$/ do |field| + element = find_field(field) + classes = element.find(:xpath, '..')[:class].split(' ') + if classes.respond_to? :should + classes.should_not include('field_with_errors') + classes.should_not include('error') + else + assert !classes.include?('field_with_errors') + assert !classes.include?('error') end end Then /^the "([^"]*)" checkbox(?: within (.*))? should be checked$/ do |label, parent| with_scope(parent) do