RSpec和"未初始化的常量特征"错误

时间:2015-10-16 19:19:58

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

当我运行rspec测试时,我得到:

  

/home/jasiek/Desktop/katowice-ror-workshops-2015/spec/support/features.rb:2:in阻止':未初始化的常量功能(NameError)

我认为问题仅出现在我的本地计算机上,因为这是来自信任源的回购(另一个用户没有遇到此问题)。我正在谈论的回购:https://github.com/netguru-training/katowice-ror-workshops-2015

我在Stack上看到问题可能会遗漏:

Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }

但我已经明白了。

哪里可能有问题?

这是来自控制台的整个日志:

  

jasiek @ jasiek-HP-EliteBook-8470p:〜/ Desktop / katowice-ror-workshops-2015 $ RAILS_ENV = test bundle exec rspec   /home/jasiek/Desktop/katowice-ror-workshops-2015/spec/support/features.rb:2:in block in <top (required)>': uninitialized constant Features (NameError) from /home/jasiek/.rvm/gems/ruby-2.2.0-preview1/gems/rspec-core-3.3.0/lib/rspec/core.rb:97:in configure&#39;       来自/home/jasiek/Desktop/katowice-ror-workshops-2015/spec/support/features.rb:1:in <top (required)>' from /home/jasiek/Desktop/katowice-ror-workshops-2015/spec/rails_helper.rb:23:in阻止&#39;       来自/home/jasiek/Desktop/katowice-ror-workshops-2015/spec/rails_helper.rb:23:in each' from /home/jasiek/Desktop/katowice-ror-workshops-2015/spec/rails_helper.rb:23:in&#39;       来自/home/jasiek/.rvm/gems/ruby-2.2.0-preview1/gems/rspec-core-3.3.0/lib/rspec/core/configuration.rb:1280:in require' from /home/jasiek/.rvm/gems/ruby-2.2.0-preview1/gems/rspec-core-3.3.0/lib/rspec/core/configuration.rb:1280:in阻止要求=&#39;       来自/home/jasiek/.rvm/gems/ruby-2.2.0-preview1/gems/rspec-core-3.3.0/lib/rspec/core/configuration.rb:1280:in each' from /home/jasiek/.rvm/gems/ruby-2.2.0-preview1/gems/rspec-core-3.3.0/lib/rspec/core/configuration.rb:1280:in要求=& #39;       来自/home/jasiek/.rvm/gems/ruby-2.2.0-preview1/gems/rspec-core-3.3.0/lib/rspec/core/configuration_options.rb:109:in block in process_options_into' from /home/jasiek/.rvm/gems/ruby-2.2.0-preview1/gems/rspec-core-3.3.0/lib/rspec/core/configuration_options.rb:108:in每个&#39 ;       来自/home/jasiek/.rvm/gems/ruby-2.2.0-preview1/gems/rspec-core-3.3.0/lib/rspec/core/configuration_options.rb:108:in process_options_into' from /home/jasiek/.rvm/gems/ruby-2.2.0-preview1/gems/rspec-core-3.3.0/lib/rspec/core/configuration_options.rb:21:in configure&#39 ;       来自/home/jasiek/.rvm/gems/ruby-2.2.0-preview1/gems/rspec-core-3.3.0/lib/rspec/core/runner.rb:101:in setup' from /home/jasiek/.rvm/gems/ruby-2.2.0-preview1/gems/rspec-core-3.3.0/lib/rspec/core/runner.rb:88:in run&#39 ;       来自/home/jasiek/.rvm/gems/ruby-2.2.0-preview1/gems/rspec-core-3.3.0/lib/rspec/core/runner.rb:73:in run' from /home/jasiek/.rvm/gems/ruby-2.2.0-preview1/gems/rspec-core-3.3.0/lib/rspec/core/runner.rb:41:in调用&#39 ;       来自/home/jasiek/.rvm/gems/ruby-2.2.0-preview1/gems/rspec-core-3.3.0/exe/rspec:4:in <top (required)>' from /home/jasiek/.rvm/gems/ruby-2.2.0-preview1/bin/rspec:23:in loading&#39;       来自/home/jasiek/.rvm/gems/ruby-2.2.0-preview1/bin/rspec:23:in <main>' from /home/jasiek/.rvm/gems/ruby-2.2.0-preview1/bin/ruby_executable_hooks:15:in eval&#39;       来自/home/jasiek/.rvm/gems/ruby-2.2.0-preview1/bin/ruby_executable_hooks:15:in`&#39;

2 个答案:

答案 0 :(得分:1)

尝试在spec/support/features.rb文件中添加以下内容:

require '../../spec/support/features/session_helpers'

所以,它变成了:

require '../../spec/support/features/session_helpers'

RSpec.configure do |config|
  config.include Features::SessionHelpers, type: :feature
end

答案 1 :(得分:0)

我知道它迟到了。

但对于其他可能来这里寻找答案的人。我面临同样的问题。 所以,当我在规范中检查rails_helper.rb文件时,我发现了这一行

Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }

最初被评论,所以我没有评论它,一切正常。 我正在使用

gem 'capybara', '~> 2.15', '>= 2.15.4'
gem 'rspec-rails', '~> 3.6'