2012-12-11 135 views
4

试图用RSpec和水豚测试OmniAuth,完全失败。我应该如何用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' => '[email protected]' 
                  } 
                 }) 

而且我知道我需要把水豚测试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搜索了一个多小时,没有运气。帮帮我?

回答

3

经过相当多的阅读,我终于设法解决这个问题。测试现在这样读取:

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 

简单!

相关问题