尝试使用 RSpec 和 Capybara 测试 OmniAuth,完全失败。
到目前为止,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'
}
})
而且我知道我需要将 Capybara 测试放在spec/features
. 所以我有:
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
但我得到:
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)>'
彻底的,彻底的迷失了。浏览了 OmniAuth wiki,它真的没有帮助;通过 Stack Overflow 搜索了一个多小时,没有运气。帮助?