我想通过Facebook测试我的登录。我使用纯粹omniauth,W/O设计。我查维基页面和做以下:omniauth模拟Facebook的响应
帮手要求规格
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.[]
我的错误在哪里?
如果我注释掉的部分与我的模拟和主机比行为没有改变(只剩enable_test_mode = TRUE)。似乎omniauth只是没有看到我的模拟:| –
你的会话控制器和用户模型是什么样的? – azolotov