我写了这个简单的规范:
it "redirects to dashboard upon login" do
user = Factory(:user)
visit "/users/sign_in
为什么我会收到此错误?
Failure/Error: visit "/users/sign_in"
ActionView::Template::Error:
undefined method `user_omniauth_authorize_path' for #<#<Class:0x00000102947cc8>:0x0000010293def8>
我的spec_helper:
OmniAuth.config.test_mode = true
OmniAuth.config.add_mock(:facebook, {:user_info => {:name => "Joe Smith", :nickname => 'joesmith'}, :uid => '123456790'})
并设计规范助手:
module DeviseSpecHelper
RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
end
def login_with_oauth(service = :facebook)
visit "/auth/#{service}"
end
end
答案 0 :(得分:0)
今天晚上我得到了同样的错误。在我的config / initializers / devise.rb文件中,我为开发和生产设置了twitter和facebook,但我没有任何测试。在为测试环境设置一些垃圾数据后,一切正常。
这是我在devise.rb初始化程序中使用的,删除了真实密钥。
if Rails.env.production?
config.omniauth :twitter, '7630184729174927491732', 'asdfia8akfuoiafo8uasdfjad;lsfjalsf'
config.omniauth :facebook, '4759010482048301849821', 'asdfawer82395ahusfi8afier98hakfdha'
else
config.omniauth :twitter, '1231231231231231231231', 'slakjsdflakhsldiuvalejhiubsdlfkjhasdfjasdl'
config.omniauth :facebook, '123123123123123', 's4s4aeraw4rert4f4awefa34afw4a4f3'
end