Ruby on rails NoMethodError:未定义的方法“sign#u in';对于#<;RSpec::ExampleGroups::Authorization::WhenSignedIn::GETIndex:0x834c9d88>;
我尝试登录用户,用Desive在Rspec中测试它。 现在我有:Ruby on rails NoMethodError:未定义的方法“sign#u in';对于#<;RSpec::ExampleGroups::Authorization::WhenSignedIn::GETIndex:0x834c9d88>;,ruby-on-rails,rspec,devise,Ruby On Rails,Rspec,Devise,我尝试登录用户,用Desive在Rspec中测试它。 现在我有: user = FactoryGirl.create(:user) sign_in user 我得到一个错误 NoMethodError: undefined method `sign_in' for #<RSpec::ExampleGroups::Authorization::WhenSignedIn::GETIndex:0x8374cc2c> # ./spec/features/authorization
user = FactoryGirl.create(:user)
sign_in user
我得到一个错误
NoMethodError:
undefined method `sign_in' for #<RSpec::ExampleGroups::Authorization::WhenSignedIn::GETIndex:0x8374cc2c>
# ./spec/features/authorization_spec.rb
添加到designe和rails\u helper以下行:
config.include Devise::TestHelpers, type: :controller
config.include Devise::TestHelpers, type: :view
以及其他方式。最终工作原理如下:
@user ||= FactoryGirl.create :user
post_via_redirect user_session_path, 'user[email]' => @user.email, 'user[password]' => @user.password
@user ||= FactoryGirl.create :user
page.driver.post new_user_session_path, 'user[email]' => @user.email, 'user[password]' => 'password123'
感谢@Arun Kumar终于可以这样工作了:
@user ||= FactoryGirl.create :user
post_via_redirect user_session_path, 'user[email]' => @user.email, 'user[password]' => @user.password
@user ||= FactoryGirl.create :user
page.driver.post new_user_session_path, 'user[email]' => @user.email, 'user[password]' => 'password123'
感谢@Arun Kumar你看了吗?你看了吗?