如何摆脱未初始化的常量Omniauth(NameError)?

时间:2015-07-05 16:06:18

标签: ruby-on-rails rspec rails-composer

我有一个全新的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>'

这给了我很多麻烦。

EDIT。 我的gem文件包含:

gem 'omniauth'
gem 'omniauth-facebook'

这是一个使用rails-composer生成的新应用,没有自定义代码。

4 个答案:

答案 0 :(得分:3)

您应该在require_relative 'helpers/omniauth'的开头添加spec/support/helpers.rb - 对我有效。

答案 1 :(得分:3)

我遇到了同样的错误,并且必须包含该行

require 'omniauth'

在specs / spec_helper.rb文件的开头,以使其正常工作。

答案 2 :(得分:0)

我相信OmniAuth类的资本是“A”。如果不是这样,请检查您的GemFile是否正确添加了宝石。

答案 3 :(得分:0)

omniauth gem与其他宝石一起使用,即如果你想使用facebook,twitter,你也需要添加其他宝石。

  gem 'omniauth'
  gem 'omniauth-twitter'
  gem 'omniauth-facebook'