DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Cucumber Testing Authentication

03.26.2009
| 4556 views |
  • submit to reddit
        
//top of steps file or in seperate factory file
require 'factory_girl'

Factory.define :user do |u|
  u.login 'the_login'
  u.email 'email@emailacc.com'
  u.password 'password'
  u.password_confirmation 'password'
# u.activated_at 'active'
end

// in steps file
Given /I am logged in as a user/ do

  user = Factory(:user)
  #when registration required
  #user.register!
  user.activate!
  visits "/login"
  fill_in("login", :with => user.login)
  fill_in("password", :with => user.password)
  click_button("Log in")
  response.body.should =~ /Logged in successfully/

end