1

我有一个新的 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 生成的全新应用程序,没有自定义代码。

4

4 回答 4

4

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

require 'omniauth'

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

于 2015-08-18T02:42:04.630 回答
3

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

于 2015-07-18T19:31:06.290 回答
0

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

于 2015-07-05T17:36:36.010 回答
0

omn​​iauth gem 可与其他 gem 一起使用,即如果您想使用 facebook、twitter,您还需要添加其他 gem。

  gem 'omniauth'
  gem 'omniauth-twitter'
  gem 'omniauth-facebook'
于 2015-07-05T18:03:08.690 回答