[英]Why is Rails running in development mode during rake test task?
Why is the following Rake task being run in Rails' development environment?为什么以下 Rake 任务会在 Rails 的开发环境中运行?
namespace :app_tests do
desc "Run unit tests."
task unit: [:environment] do
RAILS_ENV = "test"
Rails.env = "test"
system "rake test RAILS_ENV=test"
end
end
I was running into require
errors caused by missing (test group) dependencies and it turns out that's because app_tests:unit
is being run in Rails' development environment when run using bundle exec rake app_tests:unit
.我
app_tests:unit
了由于缺少(测试组)依赖项而导致的require
错误,结果证明这是因为app_tests:unit
在使用bundle exec rake app_tests:unit
运行时正在 Rails 的开发环境中运行。
How can I force this task to run in Rails' test environment?如何强制此任务在 Rails 的测试环境中运行?
Development environmnet is run by default, you need to declare the testing environment explicitly RAILS_ENV=test rake app_tests:unit
开发环境默认运行,需要显式声明测试环境
RAILS_ENV=test rake app_tests:unit
You can enforce the env var in your task specifically by doing something like what they did with rspec/core
here您可以通过执行类似于此处对
rspec/core
执行的操作来专门在您的任务中强制执行 env var
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.