First off - I know that this is 开发者_如何学运维generally horrible practice, because Cucumber is meant to only test outputs. I just want to do this for one veryveryvery specific case.
I have an app that handles user authentication using a cookie set by another app I maintain. I'd like to write a very simple integration test for authentication:
Given I have logged as "some_user" on the SSO server
When I visit any page
Then I should be logged in as "some_user"
My current step definition for the Then is as follows:
Then /^I should be logged in as "([^"]*)"$/ do |username|
user = User.find_by_username(username)
assert_equal @controller.current_user, user
end
Obviously, this is failing with "Undefined method 'current_user' for nil:NilClass".
In case it's not obvious - ApplicationController#current_user returns either the user currently logged in or nil.
You can visit some page where currently logged on user's name is displayed.
Like:
When I go to the account page
Then I should see "Welcome user" within "div#login"
精彩评论