Omniauth mock facebook answer

I want to check my login via facebook. I use pure omniauth, without development. I check the wiki page and do the following:

for query specifications

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' } }) 

my specification

 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 

But nothing returns in spec instead of my layout, I got an error:

 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.[] 

Where is my mistake?

+7
source share
2 answers

My problem was in the layout, it has the wrong structure.

 OmniAuth.config.mock_auth[:facebook] = { 'user_info' => { 'name' => 'Mario Brothers', 'image' => '', 'email' => ' dpsk@email.ru ' }, 'uid' => '123545', 'provider' => 'facebook', 'credentials' => {'token' => 'token'} } 
+10
source

This structure worked for me (December 2016)

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

All Articles