使用omniauth和rspec测试设备时出错
我写了这个简单的规范:
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
I wrote this simple spec :
it "redirects to dashboard upon login" do
user = Factory(:user)
visit "/users/sign_in
why am I getting this error?
Failure/Error: visit "/users/sign_in"
ActionView::Template::Error:
undefined method `user_omniauth_authorize_path' for #<#<Class:0x00000102947cc8>:0x0000010293def8>
my spec_helper:
OmniAuth.config.test_mode = true
OmniAuth.config.add_mock(:facebook, {:user_info => {:name => "Joe Smith", :nickname => 'joesmith'}, :uid => '123456790'})
and devise spec helper:
module DeviseSpecHelper
RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
end
def login_with_oauth(service = :facebook)
visit "/auth/#{service}"
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
今天晚上我也遇到了同样的错误。在我的 config/initializers/devise.rb 文件中,我为开发和生产设置了 twitter 和 facebook,但我没有任何用于测试的内容。在为测试环境设置了一些垃圾数据后,一切正常。
这就是我在 devise.rb 初始值设定项中使用的内容,删除了真正的键。
I was getting that very same error this evening. In my config/initializers/devise.rb file I had twitter and facebook set up for both dev and production, but I didn't have anything for test. After setting up some rubbish data for the testing environment, everything worked.
This is what I'm using in my devise.rb initializer, with real keys removed.