我有root/vendor/app_name/lib/qa.rb
存储的模块和root/vendor/app_name/lib/qa.rake
这是qa.rb
module QA
include Module1, Module2
...
end
我的佣金任务的顶部有require 'qa'
Module2和Module1都存储在root/vendor/app_name/app/models/module_name
当我运行存储在root/spec/app_name/unit/qa/qa_spec.rb
中的测试时,测试通过。
当我运行调用qa.rb中的方法的rake任务时,我收到以下错误:
NameError: uninitialized constant QA::Module1
/root/vendor/app_name/lib/qa.rb:2:in `<module:QA>'
/root/vendor/app_name/lib/qa.rb:1:in `<top (required)>'
/root/vendor/app_name/lib/tasks/qa.rake:2:in `block in <top (required)>'
/root/vendor/app_name/lib/tasks/qa.rake:1:in `<top (required)>'
/var/lib/gems/2.1.0/gems/zeus-0.15.3/lib/zeus/load_tracking.rb:50:in `load'
/var/lib/gems/2.1.0/gems/zeus-0.15.3/lib/zeus/load_tracking.rb:50:in `load'
/var/lib/gems/2.1.0/gems/zeus-0.15.3/lib/zeus/load_tracking.rb:43:in `load'
/var/lib/gems/2.1.0/gems/railties-4.1.8/lib/rails/engine.rb:654:in `block in run_tasks_blocks'
/var/lib/gems/2.1.0/gems/railties-4.1.8/lib/rails/engine.rb:654:in `each'
/var/lib/gems/2.1.0/gems/railties-4.1.8/lib/rails/engine.rb:654:in `run_tasks_blocks'
/var/lib/gems/2.1.0/gems/railties-4.1.8/lib/rails/application.rb:383:in `block in run_tasks_blocks'
/var/lib/gems/2.1.0/gems/railties-4.1.8/lib/rails/engine/railties.rb:13:in `each'
/var/lib/gems/2.1.0/gems/railties-4.1.8/lib/rails/engine/railties.rb:13:in `each'
/var/lib/gems/2.1.0/gems/railties-4.1.8/lib/rails/application.rb:383:in `run_tasks_blocks'
/var/lib/gems/2.1.0/gems/railties-4.1.8/lib/rails/engine.rb:449:in `load_tasks'
/vagrant/Rakefile:6:in `<top (required)>'
为什么我在这里收到此错误但在我的测试中没有?
答案 0 :(得分:0)
尝试将rake任务描述为
task qa: :environment do
...
end
这将告诉rake加载应用程序环境