2012-12-11 67 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 

簡單!

相關問題