I have a simple Cucumber test to see if, on entering invalid credentials, a user is sent back to the registration page.
My final step looks like this:
Then /^I should be on the registration page$/ do
current_path.should == new_user_registration_path
end
However, when someone submits a form and it comes back with errors, they actually end up on “/users”, and not “/users/sign_up”
I’m assuming this is because the user_registration POST method maps to /users. But I don’t wait to test for /users, because that could theoretically be the index of users, which I don’t want to be the error page.
Is there a better way to test form errors in Rails?
You should test that the page that user ends up on contains error text. Treat Cucumber tests as if you were testing manually: you wouldn’t check the url after form submission, but you would look in the page content to understand if the submission was successful or not