Reputation: 714
I wanna test my functionals in my rails application, but the tests require a user/admin to be logged in. I have looked at many websites, but I cannot grasp what I really should be doing to make it work. I'm sure there there is an easy thing to do, but I cannot seem to find it.
I have seen the stubs command used, but I only get that it is an undefined method and I don't really know what it is supposed to do.
Any ideas on how I can run my tests as if it was an user/admin requesting them?
Thanks for any help I might get.
Upvotes: 1
Views: 529
Reputation: 7403
If you're using cucumber, just login as the user. Something like:
fill_in 'users[username]', :with => "my username" fill_in 'users[password]', :with => "my password" click_button "Log In"
If you're using rspec+capybara, you can do something like this (assuming you're using Devise for authentication)
# spec/spec_helper.rb
include Warden::Test::Helpers
# in spec/acceptance/some_spec.rb
...
login_as FactoryGirl.create(:user)
session
object, or by stubbing out current_user
(assuming you call it that) Upvotes: 1