I have a step definition in my cucumber test suite that authenticates the user and to try and speed up my test suite, I want this step to check the user is already authenticated. Perhaps this is a bad idea because it means tests may depend on each other… I don’t know. But how would I do this? I am not fluent in Ruby, unfortunately.
I am hoping that I can render a class in the DOM so I can test against this with have_selector or something. This might also be a bad idea too…
Given /^I am authenticated as a "([^"]*)" user$/ do |role|
#TODO: only do this if the user is not authenticated
visit('/login')
fill_in "name", :with => "something"
fill_in "pass", :with => "password"
click_button
response_body.should contain("Log out")
end
You’re right this would be a bad idea. But if you really want to do it the correct way would be checking any kind of text on the page, for example you can have status bar with logged in username. This would be correct way because it simulates the behavior of a human, something like – oh, here is my username – it means that I’m already logged in:)
Here is how your step could look like: