简体   繁体   中英

Why is Rails running in development mode during rake test task?

Why is the following Rake task being run in Rails' development environment?

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 .

How can I force this task to run in Rails' test environment?

Development environmnet is run by default, you need to declare the testing environment explicitly 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM