Last time we should you how to create the mock user using the Factory Girl ♥ Rails gem.
Rails – Create Mock Data for RSpec
Recalled that spec file.
describe "for an authorized user" do before(:each) do # Create the user object by factory @user = Factory(:user) # Sign in the yser test_sign_in(@user) end ...
The above codes use the test_sign_in() function which is defined in the <rails_project_root>/spec/spec_helper.rb
RSpec.configure do |config| def test_sign_in(user) user.confirm! controller.sign_in(user) end
I need to confirm the user before sign in because i have enabled the :confirmable setting in app/models/user.rb. otherwise you will get the following error.
Failure/Error: @user = test_sign_in(Factory(:user))
uncaught throw :warden
Done =)
Reference: StackOverflow – RSpec-2 and Devise