1

I try to sign in user to test it in Rspec with Devise. Right now I have:

user = FactoryGirl.create(:user)
sign_in user

And I get an error

 NoMethodError:
   undefined method `sign_in' for #<RSpec::ExampleGroups::Authorization::WhenSignedIn::GETIndex:0x8374cc2c>
 # ./spec/features/authorization_spec.rb

I have read some SO questions and some devise docs about testing(Like this)

So far I tried some various ways, but still didn't manage it to work. If neccessary I can also list them here, but they tend to new errors and complications. So what do I do to make it all work?

LONG STORY: Things I have tried:

Trying something like this:

@user ||= FactoryGirl.create :user
post_via_redirect user_session_path, 'user[email]' => @user.email, 'user[password]' => @user.password

Adding to devise and rails_helper this lines:

  config.include Devise::TestHelpers, type: :controller
  config.include Devise::TestHelpers, type: :view

And other ways.

user2950593
  • 9,233
  • 15
  • 67
  • 131

1 Answers1

0

Finally works like this:

@user ||= FactoryGirl.create :user
page.driver.post new_user_session_path, 'user[email]' => @user.email, 'user[password]' => 'password123'

Thanks to @Arun Kumar

user2950593
  • 9,233
  • 15
  • 67
  • 131