簡體   English   中英

Railsapp OAuth教程,rspec“統一常量”錯誤

[英]Railsapp OAuth Tutorial, rspec “unitialized constant” error

在學習完本教程之后,我在路徑下創建了一個文件omniauth.rb。

規范/支持/幫助者/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”時,出現完全相同的錯誤。

在本教程的某一點,您可以選擇在/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為該應用程序成功運行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM