如何摆脱未初始化的常量 Omniauth (NameError)?
How to get rid of uninitialized constant Omniauth (NameError)?
我有一个新的 rails-composer omniauth 应用程序。当 运行 使用 rspec 进行测试时,会出现此错误:
$ rspec
/home/grzegorz/programing/integra/spec/support/helpers.rb:5:in `block in <top (required)>': uninitialized constant Omniauth (NameError)
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/gems/rspec-core-3.3.1/lib/rspec/core.rb:97:in `configure'
from /home/grzegorz/programing/integra/spec/support/helpers.rb:4:in `<top (required)>'
from /home/grzegorz/programing/integra/spec/rails_helper.rb:23:in `block in <top (required)>'
from /home/grzegorz/programing/integra/spec/rails_helper.rb:23:in `each'
from /home/grzegorz/programing/integra/spec/rails_helper.rb:23:in `<top (required)>'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/gems/rspec-core-3.3.1/lib/rspec/core/configuration.rb:1280:in `require'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/gems/rspec-core-3.3.1/lib/rspec/core/configuration.rb:1280:in `block in requires='
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/gems/rspec-core-3.3.1/lib/rspec/core/configuration.rb:1280:in `each'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/gems/rspec-core-3.3.1/lib/rspec/core/configuration.rb:1280:in `requires='
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/gems/rspec-core-3.3.1/lib/rspec/core/configuration_options.rb:109:in `block in process_options_into'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/gems/rspec-core-3.3.1/lib/rspec/core/configuration_options.rb:108:in `each'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/gems/rspec-core-3.3.1/lib/rspec/core/configuration_options.rb:108:in `process_options_into'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/gems/rspec-core-3.3.1/lib/rspec/core/configuration_options.rb:21:in `configure'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/gems/rspec-core-3.3.1/lib/rspec/core/runner.rb:101:in `setup'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/gems/rspec-core-3.3.1/lib/rspec/core/runner.rb:88:in `run'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/gems/rspec-core-3.3.1/lib/rspec/core/runner.rb:73:in `run'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/gems/rspec-core-3.3.1/lib/rspec/core/runner.rb:41:in `invoke'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/gems/rspec-core-3.3.1/exe/rspec:4:in `<top (required)>'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/bin/rspec:23:in `load'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/bin/rspec:23:in `<main>'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/bin/ruby_executable_hooks:15:in `eval'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/bin/ruby_executable_hooks:15:in `<main>'
调试起来很麻烦
编辑。
我的 gem 文件有那些:
gem 'omniauth'
gem 'omniauth-facebook'
这是使用 rails-composer 生成的全新应用,没有自定义代码。
我相信 OmniAuth class 大写 "A"。如果不是这样,请检查您的 GemFile 是否正确添加了 gem。
omniauth gem 与其他 gem 一起使用,即如果您想使用 facebook、twitter,您也需要添加其他 gem。
gem 'omniauth'
gem 'omniauth-twitter'
gem 'omniauth-facebook'
您应该在 spec/support/helpers.rb
的开头添加 require_relative 'helpers/omniauth'
- 适合我。
我遇到了同样的错误,必须包含行
require 'omniauth'
在 specs/spec_helper.rb 文件的开头使其工作。
我有一个新的 rails-composer omniauth 应用程序。当 运行 使用 rspec 进行测试时,会出现此错误:
$ rspec
/home/grzegorz/programing/integra/spec/support/helpers.rb:5:in `block in <top (required)>': uninitialized constant Omniauth (NameError)
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/gems/rspec-core-3.3.1/lib/rspec/core.rb:97:in `configure'
from /home/grzegorz/programing/integra/spec/support/helpers.rb:4:in `<top (required)>'
from /home/grzegorz/programing/integra/spec/rails_helper.rb:23:in `block in <top (required)>'
from /home/grzegorz/programing/integra/spec/rails_helper.rb:23:in `each'
from /home/grzegorz/programing/integra/spec/rails_helper.rb:23:in `<top (required)>'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/gems/rspec-core-3.3.1/lib/rspec/core/configuration.rb:1280:in `require'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/gems/rspec-core-3.3.1/lib/rspec/core/configuration.rb:1280:in `block in requires='
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/gems/rspec-core-3.3.1/lib/rspec/core/configuration.rb:1280:in `each'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/gems/rspec-core-3.3.1/lib/rspec/core/configuration.rb:1280:in `requires='
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/gems/rspec-core-3.3.1/lib/rspec/core/configuration_options.rb:109:in `block in process_options_into'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/gems/rspec-core-3.3.1/lib/rspec/core/configuration_options.rb:108:in `each'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/gems/rspec-core-3.3.1/lib/rspec/core/configuration_options.rb:108:in `process_options_into'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/gems/rspec-core-3.3.1/lib/rspec/core/configuration_options.rb:21:in `configure'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/gems/rspec-core-3.3.1/lib/rspec/core/runner.rb:101:in `setup'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/gems/rspec-core-3.3.1/lib/rspec/core/runner.rb:88:in `run'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/gems/rspec-core-3.3.1/lib/rspec/core/runner.rb:73:in `run'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/gems/rspec-core-3.3.1/lib/rspec/core/runner.rb:41:in `invoke'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/gems/rspec-core-3.3.1/exe/rspec:4:in `<top (required)>'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/bin/rspec:23:in `load'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/bin/rspec:23:in `<main>'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/bin/ruby_executable_hooks:15:in `eval'
from /home/grzegorz/.rvm/gems/ruby-2.2.2@integra/bin/ruby_executable_hooks:15:in `<main>'
调试起来很麻烦
编辑。 我的 gem 文件有那些:
gem 'omniauth'
gem 'omniauth-facebook'
这是使用 rails-composer 生成的全新应用,没有自定义代码。
我相信 OmniAuth class 大写 "A"。如果不是这样,请检查您的 GemFile 是否正确添加了 gem。
omniauth gem 与其他 gem 一起使用,即如果您想使用 facebook、twitter,您也需要添加其他 gem。
gem 'omniauth'
gem 'omniauth-twitter'
gem 'omniauth-facebook'
您应该在 spec/support/helpers.rb
的开头添加 require_relative 'helpers/omniauth'
- 适合我。
我遇到了同样的错误,必须包含行
require 'omniauth'
在 specs/spec_helper.rb 文件的开头使其工作。