使用omniauth和rspec测试设备时出错

发布于 2024-12-04 11:30:57 字数 834 浏览 0 评论 0原文

我写了这个简单的规范:

  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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长亭外,古道边 2024-12-11 11:30:57

今天晚上我也遇到了同样的错误。在我的 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

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.

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文