0

特定のリクエストを行うテストを書いたのは、Devise & OmniauthのGoogle OAuth2システムを使用してログインするログインユーザーだけでした。私はOmniauth Wiki page about Integration Tests supportomniauthを取得して、リクエスト仕様のログインを模擬しました。

から例を取り上げここで私はなぜか、どこから失敗しているに多くを解読することはできません言うべきスペック

describe "allows logged in users" do 
    before(:each) do 
      OmniAuth.config.test_mode = true 
      OmniAuth.config.add_mock(:google, {:uid => '12345'}) 
      Rails.application.env_config["devise.mapping"] = Devise.mappings[:user] 
      Rails.application.env_config["omniauth.auth"] = OmniAuth.config.mock_auth[:google] 
    end 

    it "new certification form" do 
     get new_certification_path 
     expect(response).to be_success 
    end 

    it "to create certification" do 
     certification_attributes = FactoryGirl.attributes_for :certification 
     expect { 
      post "/certifications", params: { certification: certification_attributes } 
     }.to change(Certification, :count) 

     expect(response).to redirect_to certification_path 
    end 

    end 

言うまでもなくだ、ログインしているユーザーの復帰にomniauth模擬する方法を見つけることができません与えられたエラーが、私は、ユーザーが、私はこれはになり、間違った設定

を使用していた

Failures: 

    1) Certifications allows logged in users new certification form 
    Failure/Error: expect(response).to be_success 
     expected `#<ActionDispatch::TestResponse:0x007fb23b4c2990 @mon_owner=nil, @mon_count=0, @mon_mutex=#<Thread::Mu..., @method=nil, @request_method=nil, @remote_ip=nil, @original_fullpath=nil, @fullpath=nil, @ip=nil>>.success?` to return true, got false 
    # ./spec/requests/certifications_spec.rb:49:in `block (3 levels) in <top (required)>' 

    2) Certifications allows logged in users to create certification 
    Failure/Error: 
     expect { 
     post "/certifications", params: { certification: certification_attributes } 
     }.to change(Certification, :count) 

     expected #count to have changed, but is still 0 
    # ./spec/requests/certifications_spec.rb:54:in `block (3 levels) in <top (required)>' 

答えて

0

にログインすることはできませんので、それがあると仮定します次いで

OmniAuth.config.test_mode = true 
    OmniAuth.config.mock_auth[:google_oauth2] = OmniAuth::AuthHash.new({ 
     :provider => "google_oauth2", 
     :uid => "123456789", 
     :info => { 
     :name => "Tony Stark", 
     :email => "[email protected]" 
     }, 
     :credentials => { 
     :token => "token", 
     :refresh_token => "refresh token" 
     } 
    } 
) 

および方法前

before(:each) do 
     Rails.application.env_config["devise.mapping"] = Devise.mappings[:user] 
     Rails.application.env_config["omniauth.auth"] = OmniAuth.config.mock_auth[:google_oauth2] 
end 
関連する問題