omn​​iauth模拟facebook响应

Mik*_*kin 7 facebook rspec ruby-on-rails mocking omniauth

我想通过Facebook测试我的登录信息.我使用纯粹的omniauth,没有设计.我检查维基页面并执行以下操作:

请求规格的助手

module IntegrationSpecHelper
  def login_with_oauth(service = :facebook)
    visit "/auth/#{service}"
  end
end
Run Code Online (Sandbox Code Playgroud)

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'
      }
})
Run Code Online (Sandbox Code Playgroud)

我的规格

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
Run Code Online (Sandbox Code Playgroud)

但在规范中没有任何返回而不是我的模拟我得到一个错误:

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.[]
Run Code Online (Sandbox Code Playgroud)

我的错误在哪里?

Mik*_*kin 10

我的问题是在模拟,它有错误的结构.

OmniAuth.config.mock_auth[:facebook] = {
  'user_info' => {
    'name' => 'Mario Brothers',
    'image' => '',
    'email' => 'dpsk@email.ru' },
  'uid' => '123545',
  'provider' => 'facebook',
  'credentials' => {'token' => 'token'}
}
Run Code Online (Sandbox Code Playgroud)