2012-11-02 9 views
4

에 대한 통합 테스트에서 나는에 Omniauth 테스트 모드가:</p> <p><strong>spec_helper (내가 바로 <code>end</code> 전에 파일의 맨 아래에 넣어) :</strong> OmniAuth

#Turn on "test mode" for OmniAuth 
OmniAuth.config.test_mode = true 

이 내 테스트입니다 :

사양/요청/authorization_pages_spec.rb :

나는 내 테스트를 실행할 때
describe "signin" do 
    before { visit signin_path } 
    . 
    . 
    . 
    describe "with OmniAuth" do 
     before do 
     OmniAuth.config.add_mock :facebook, uid: "fb-12345", info: { name: "Bob Smith" } 
     visit root_path 
     end 

     describe "Facebook provider" do 
     before do 
      request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:facebook] 
      click_link "Sign in with Facebook" 
     end 

     it { should have_selector('title', text: user.name) } 

     it { should have_link('Users', href: users_path) } 
     it { should have_link('Profile', href: user_path(user)) } 
     it { should have_link('Settings', href: edit_user_path(user)) } 
     it { should have_link('Sign out', href: signout_path) } 

     it { should_not have_link('Sign in', href: signin_path) } 
     end 

난이 얻을 :

실패 :

1) Authentication signin with OmniAuth Facebook provider 
    Failure/Error: request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:facebook] 
    NoMethodError: 
     undefined method `env' for nil:NilClass 
    # ./spec/requests/authentication_pages_spec.rb:57:in `block (5 levels) in <top (required)>' 

(등).

누락되었거나 잘못된 것입니까?

+0

이것을 알아 냈습니까? 나는 같은 문제가있다. ... – Brandon

+0

@Brandon 잠을 2 주 후에, 나는 포기했다. 그리고 새로운 규칙을 채택했습니다 : 보석을 시험하지 마십시오. 그렇지 않으면 시험을 싫어하게 될 것입니다. – alexchenco

답변

2

이 예제에서는 두 가지 다른 것을 혼합한다고 생각합니다. 통합 스펙을 작성하려고 시도하지만 request 메소드 AFAIK는 제어기 스펙 (spec/controllers 디렉토리의 스펙 용)에서만 사용 가능합니다. 따라서 undefined method env 'for nil : NilClass` 오류가 발생했습니다.

내 샘플 프로젝트 건강한 OmniAuth 통합 사양을 찾을 수 : https://github.com/lucassus/locomotive/blob/9cd7dfd365469fc70fc367f29705a56df9730f6f/spec/features/user_facebook_sign_in_spec.rb

를 내가 당신을 도울 것입니다 바랍니다.

+0

요청 사양이 아닌 기능 사양이 아닌가요? – iainbeeston