public
Last active

Cucumber Step definitions for testing a form that uses jquery's validator plugin

  • Download Gist
jquery_validate_steps.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
# goes in features/step_definitions
Then /^I should see the "([^"]*)" error for "([^"]*)"$/ do |error, label|
field = find_field(label)
html_label = find("label[for=#{field[:id]}][class=error]")
html_label.text.should eql(error)
end
 
Then /^I should not see errors for "([^"]*)"$/ do |label|
field = find_field(label)
lambda {find("label[for=#{field[:id]}][class=error]")}.should raise_error(Capybara::ElementNotFound)
end
 
# example scenario testing a Change Password form
 
@javascript
Scenario: Change password with local validation errors
Given I am a new, authenticated user
When I go to the profile page
And I press "Update"
Then I should see the "This field is required." error for "user_password"
Then I should see the "This field is required." error for "user_password_confirmation"
Then I should see the "This field is required." error for "user_current_password"
And I fill in "user_password" with "123"
Then I should see the "Please enter at least 6 characters." error for "user_password"
And I fill in "user_password" with "123456"
And I fill in "user_password_confirmation" with "12346"
Then I should see the "Does not match your password" error for "user_password_confirmation"

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.