【发布时间】:2014-08-29 15:17:03
【问题描述】:
在我当前的项目中,我无法运行任何测试用例,因为我收到以下错误:
/home/harsh/Documents/viburnix/cloud/viburnix/spec/support/helpers.rb:2:in `block in <top (required)>': uninitialized constant Features (NameError)
完整的跟踪:
/home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/http/mime_type.rb:163: warning: already initialized constant Mime::ZIP
/home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/http/mime_type.rb:163: warning: previous definition of ZIP was here
Coverage report generated for RSpec to /home/harsh/Documents/viburnix/cloud/viburnix/coverage. 11 / 56 LOC (19.64%) covered.
/home/harsh/Documents/viburnix/cloud/viburnix/spec/support/helpers.rb:2:in `block in <top (required)>': uninitialized constant Features (NameError)
from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/rspec-core-3.0.0.beta2/lib/rspec/core.rb:112:in `configure'
from /home/harsh/Documents/viburnix/cloud/viburnix/spec/support/helpers.rb:1:in `<top (required)>'
from /home/harsh/Documents/viburnix/cloud/viburnix/spec/spec_helper.rb:16:in `block in <top (required)>'
from /home/harsh/Documents/viburnix/cloud/viburnix/spec/spec_helper.rb:16:in `each'
from /home/harsh/Documents/viburnix/cloud/viburnix/spec/spec_helper.rb:16:in `<top (required)>'
from /home/harsh/Documents/viburnix/cloud/viburnix/spec/models/user_spec.rb:1:in `require'
from /home/harsh/Documents/viburnix/cloud/viburnix/spec/models/user_spec.rb:1:in `<top (required)>'
from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/rspec-core-3.0.0.beta2/lib/rspec/core/configuration.rb:932:in `load'
from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/rspec-core-3.0.0.beta2/lib/rspec/core/configuration.rb:932:in `block in load_spec_files'
from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/rspec-core-3.0.0.beta2/lib/rspec/core/configuration.rb:932:in `each'
from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/rspec-core-3.0.0.beta2/lib/rspec/core/configuration.rb:932:in `load_spec_files'
from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/rspec-core-3.0.0.beta2/lib/rspec/core/command_line.rb:21:in `run'
from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/rspec-core-3.0.0.beta2/lib/rspec/core/runner.rb:100:in `run'
from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/rspec-core-3.0.0.beta2/lib/rspec/core/runner.rb:31:in `invoke'
from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/rspec-core-3.0.0.beta2/exe/rspec:4:in `<top (required)>'
from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/bin/rspec:23:in `load'
from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/bin/rspec:23:in `<main>'
spec/spec_helper.rb是spec:install生成的标准文件,包括:
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
在spec/support/helpers.rb,我有:
RSpec.configure do |config|
config.include Features::SessionHelpers, type: :feature
config.include Mongoid::Matchers, type: :model
config.include AuthenticationHelpers, type: :controller
end
它在第 2 行给出错误:Features::SessionHelpers。
似乎根本不需要代码,或者只是没有按正确的顺序加载。
问题是在一个 7 人的团队中,我是唯一一个无法运行 spec 的人。非常需要任何帮助或指导,我们将不胜感激。
【问题讨论】:
-
我刚刚在另一个文件夹中克隆了同一个项目,运行了捆绑安装,但仍然遇到同样的错误。
-
我刚刚将 Gemfile 和 Gemfile.lock 与我团队的其他 2 位成员进行了比较。 Gemfile 和 lock 版本是相同的。 :(
-
您是否在
spec/support/features/session_helpers.rb文件中创建了Features::SessionHelpers类? -
这个blog post 可能会有所帮助.. 确保您在某处声明了一个 Features 模块,并且 SessionHelpers 在 Features 模块下的命名空间。
-
@HarshGupta 您能否验证您确实创建了具有正确命名空间的
session_helpers文件?
标签: ruby-on-rails-4 rspec-rails