Skip to content

Instantly share code, notes, and snippets.

@sgulics
Created June 30, 2011 18:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgulics/1056822 to your computer and use it in GitHub Desktop.
Save sgulics/1056822 to your computer and use it in GitHub Desktop.
Cucumber Step definitions for testing a form that uses jquery's validator plugin
# 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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment