2011-08-25 4 views
7

페이스 북을 통해 로그인을 테스트하고 싶습니다. 순수한 omniauth를 사용하여 Im, Devise. 나는 위키 페이지를 확인하고 다음을 수행하십시오 스펙 아무것도의 요구 사양에 대한omniauth mock facebook response

도우미

module IntegrationSpecHelper 
    def login_with_oauth(service = :facebook) 
    visit "/auth/#{service}" 
    end 
end 

spec_helper.rb

RSpec.configure do |config| 
     config.include IntegrationSpecHelper, :type => :request 
    end 

    Capybara.default_host = 'http://example.org' 
    OmniAuth.config.test_mode = true 
    OmniAuth.config.add_mock(:facebook, { 
    :provider => 'facebook', 
    :uid => '12345', 
    :user_info => { 
     :name => 'dpsk' 
     } 
}) 

내 사양

require 'spec_helper' 

describe 'facebook' do 
    it "should login with facebook", :js => true do 
    login_with_oauth 

    visit '/' 
    page.should have_content("dpsk") 
    end 
end 


#OmniAuth routes 
    match "/auth/:provider/callback" => "sessions#create" 
    match "/signout" => "sessions#destroy", :as => :signout 
    match "/signin" => "sessions#signin", :as => :signin 
    match "/auth/failure" => "sessions#failure", :as => :auth_failure 

그러나이 대신 반환 내 모의 나는 오류있어 :

Failure/Error: visit "/auth/facebook" 
    You have a nil object when you didn't expect it! 
You might have expected an instance of Array. 
The error occurred while evaluating nil.[] 

내 실수는 어디에 있습니까?

+0

것은 내가 내 모의와 호스트 부분을 주석 경우 행동 didnt 한 변화보다 (사실 만 enable_test_mode = 왼쪽). 옴니 아워처럼 내 모의도를 보지 못했던 것 같습니다 : | –

+0

세션 컨트롤러 및 사용자 모델은 어떻게 생겼습니까? – azolotov

답변

10

내 문제는 조롱 중이 었습니다. 구조가 잘못되었습니다.

이 구조는 나를 위해 일한
OmniAuth.config.mock_auth[:facebook] = { 
    'user_info' => { 
    'name' => 'Mario Brothers', 
    'image' => '', 
    'email' => '[email protected]' }, 
    'uid' => '123545', 
    'provider' => 'facebook', 
    'credentials' => {'token' => 'token'} 
} 
+0

올바른 구조를 게시 하시겠습니까? – ardavis

+1

확실한 이유는 무엇입니까? 내 대답은 –

+1

입니다. AuthHash 구조에 있어야합니다. 그냥'OmniAuth :: AuthHash.new ({해시 당신이}} 초기화' –

0

(2016 12월)

OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new({ 
    'provider' => 'facebook', 
    'uid' => '123545', 
    'info' => { 
    'email' => '[email protected]', 
    'name' => 'Mario Brothers', 
    'image' => '' }, 
    'credentials'=> { 
    'token'=> '12345', 
    'expires_at' => 1486718672, 
    'expires' => true }, 
    'extra' => { 
    'raw_info' => { 
     'email' => '[email protected]', 
     'name' => 'Mario Brothers', 
     'id' => '12345' } 
    } 
})