[英]How should I test Omniauth with Rspec and Capybara?
Trying to test OmniAuth with RSpec and Capybara, utterly failing. 试图用RSpec和Capybara测试OmniAuth,完全失败了。
So far, spec_helper.rb
has: 到目前为止, spec_helper.rb
有:
# Enable omniauth testing mode
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:google] = OmniAuth::AuthHash.new({
:provider => 'google',
:uid => '1337',
:info => {
'name' => 'JonnieHallman',
'email' => 'jon@test.com'
}
})
And I know I need to put Capybara tests under spec/features
. 而且我知道我需要将Capybara测试置于spec/features
之下。 So I have: 所以我有:
require 'spec_helper'
describe "Authentications" do
context "without signing into app" do
it "sign in button should lead to Google authentication page" do
visit root_path
click_link "Login"
Authentication.last.uid.should == '1337'
end
end
end
But I get: 但我得到:
1) Authentications without signing into app sign in button should lead to Google authentication page
Failure/Error: Authentication.last.uid.should == '1337'
NameError:
uninitialized constant Authentication
# ./spec/features/omniauth_spec.rb:10:in `block (3 levels) in <top (required)>'
Utterly, utterly lost. 完全失败了。 Went through the OmniAuth wiki and it really didn't help; 通过OmniAuth wiki,它真的没有帮助; searched for over an hour through Stack Overflow, no luck. 通过Stack Overflow搜索了一个多小时,没有运气。 Help? 救命?
After doing quite a bit of reading, I finally managed to fix this. 在做了很多阅读之后,我终于设法解决了这个问题。 Test now reads like this: 测试现在看起来像这样:
require 'spec_helper'
describe "Authentications" do
context "Clicking the login link" do
it "Login button should log in" do
visit root_path
click_link "Login"
page.should have_link "Logout"
end
end
end
Simple! 简单!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.