[rspec-users] Restful Authentication and Cucumber
alberto.perdomo at aentos.es
Mon Dec 8 18:37:15 EST 2008
>>> This is the step:
>>> Given /I am logged in as a user/ do
>>> @current_user = Factory.define :user do |u|
>>> u.name 'the user'
>>> u.email 'erdoss at gmail.com'
>>> u.login 'the_login'
>>> u.password 'password'
>>> u.password_confirmation 'password'
>>> visits "/login"
>>> fills_in("login", :with => "the_login")
>>> fills_in("password", :with => "password")
>>> clicks_button("Log in")
you can simplify the code to activate the user.
This is my step definition for login:
When /^i login$/ do
user = Factory(:user)
fill_in("username", :with => user.login)
fill_in("password", :with => user.password)
This is my factory code in test/factories.rb
Factory.define :user do |u|
u.email 'test at example.com'
I think i saw a fork of factory_girl somewhere that supported before
and after hooks so you could actually call the register and activate
methods after save from within the factory definition code. This way
your steps and other tests would be much cleaner. I will look further
More information about the rspec-users