[英]Railsapp OAuth Tutorial, rspec “unitialized constant” error
Following the tutorial, I created a file omniauth.rb at the path 在学习完本教程之后,我在路径下创建了一个文件omniauth.rb。
spec/support/helpers/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
But when I run rspec, I get an error with "uninitialized constant Omniauth" 但是,当我运行rspec时,出现“未初始化的常量Omniauth”错误
rails-omniauth/spec/support/helpers.rb:2:in `block in <top (required)>': uninitialized constant Omniauth (NameError)
It seems clear that either omniauth.rb or helpers.rb should be in a different location, but I don't know where. 似乎omniauth.rb或helpers.rb都应该位于其他位置,但我不知道在哪里。
Update : 更新 :
I subsequently tried installing the rails-omniauth via the Rails Composer app. 随后,我尝试通过Rails Composer应用程序安装rails-omniauth。 When I run "rspec" for this app, I get exactly the same error.
当我为此应用程序运行“ rspec”时,出现完全相同的错误。
At one point in the tutorial you are given a choice between creating a file at at /spec/support/helpers.rb
: 在本教程的某一点,您可以选择在
/spec/support/helpers.rb
处创建文件:
RSpec.configure do |config|
config.include Omniauth::Mock
config.include Omniauth::SessionHelpers, type: :feature
end
OmniAuth.config.test_mode = true
Or adding these same lines to /spec/rails_helper.rb
. 或将这些相同的行添加到
/spec/rails_helper.rb
。
I created the new file at /spec/support/helpers.rb
. 我在
/spec/support/helpers.rb
创建了新文件。 To make this work, I needed to add the line require_relative 'helpers/omniauth'
at the top of the file. 为了使这项工作有效,我需要在文件顶部添加行
require_relative 'helpers/omniauth'
。 The Rails Composer app also adds the helpers.rb
file rather than editing rails_helper.rb
, so the same line is needed to make rspec run successfully for that app. Rails Composer应用程序还添加了
helpers.rb
文件,而不是编辑rails_helper.rb
,因此需要同一行代码才能使rspec为该应用程序成功运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.