简体   繁体   English

为什么在 rake 测试任务期间 Rails 以开发模式运行?

[英]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.

相关问题 运行“ rake测试”时出错-敏捷的Rails开发手册,软件仓库 - Error while running 'rake test' - Agile rails development book, Depot 为什么我的rake任务在我的测试中运行了两次? - Why is my rake task running twice in my test? Ruby on Rails,rake db:seed或db:reset - 你如何决定哪种模式(开发/测试/生产)? - Ruby on Rails, rake db:seed or db:reset - how do you dictate which mode (development/test/production)? 如何在rails rake任务中将development_structure.sql文件导入我的测试数据库? - How do I import a development_structure.sql file into my test database in a rails rake task? Rails启动期间如何运行rake任务? - How to run rake task during rails initiation? 对于 ruby on rails 3,在生产模式下不调用 Rake 任务 - Rake task is not called in production mode for ruby on rails 3 为什么 Rails 4.2 应用程序在运行 rake db:migrate 任务期间使用 Ansible 在 Ubuntu 服务器上部署时创建具有 root 权限的日志文件 - Why Rails 4.2 app create log files with root permissions when deploy it on Ubuntu server using Ansible during running rake db:migrate task Rail3 rake测试任务没有运行测试 - Rail3 rake test task not running tests Rails:让这个rake任务知道它在测试环境中 - Rails: Make this rake task aware that it is in the test environment Rails - 在一项任务中进行 Rake 测试和 rubocop - Rails - Rake test and rubocop in one task
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM