【问题标题】:Railsapp OAuth Tutorial, rspec "unitialized constant" errorRails Api OAuth 教程,rspec “未初始化的常量”错误
【发布时间】:2016-03-10 21:47:01
【问题描述】:

按照教程,我在路径下创建了一个文件omniauth.rb

spec/support/helpers/omniauth.rb

module Omniauth

  module Mock
    def auth_mock
      OmniAuth.config.mock_auth[:twitter] = {
        'provider' => 'twitter',
        'uid' => '123545',
        'user_info' => {
          'name' => 'mockuser'
        },
        'credentials' => {
          'token' => 'mock_token',
          'secret' => 'mock_secret'
        }
      }
    end
  end

end

但是当我运行 rspec 时,出现“未初始化的常量 Omniauth”错误

rails-omniauth/spec/support/helpers.rb:2:in `block in <top (required)>': uninitialized constant Omniauth (NameError)

似乎很明显,omniauth.rb 或 helpers.rb 应该位于不同的位置,但我不知道在哪里。

更新

我随后尝试通过 Rails Composer 应用程序安装 rails-omniauth。当我为这个应用程序运行“rspec”时,我得到了完全相同的错误。

【问题讨论】:

标签: ruby-on-rails rspec oauth railsapps


【解决方案1】:

在本教程中,您可以选择在 /spec/support/helpers.rb 创建文件:

RSpec.configure do |config|
  config.include Omniauth::Mock
  config.include Omniauth::SessionHelpers, type: :feature
end
OmniAuth.config.test_mode = true

或者将这些相同的行添加到/spec/rails_helper.rb

我在/spec/support/helpers.rb 创建了新文件。为了完成这项工作,我需要在文件顶部添加行 require_relative 'helpers/omniauth'。 Rails Composer 应用程序还添加了helpers.rb 文件而不是编辑rails_helper.rb,因此需要相同的行来使该应用程序成功运行rspec。

【讨论】:

    猜你喜欢
    • 2015-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 2018-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多