繁体   English   中英

rake任务未按指定的顺序运行子任务

[英]rake task not running sub-tasks in order specified

在Rails 4.2应用中,在Rakefile中,我有以下内容:

task(:default).clear
task :default => [:test, 'bundle:audit']

输出始终始终具有bundle:audit。 这是为什么?

我在某些地方读到rake在出现依赖关系时执行任务,但是据我所知,bundle:audit不依赖于测试。 它在这里定义:

https://github.com/rubysec/bundler-audit/blob/master/lib/bundler/audit/task.rb

引用评论在Rake的GitHub存储库中讨论相同问题的评论

事实证明,您的问题是由于Rails创建测试任务的方式引起的:

 desc "Run tests quickly by merging all types and not resetting db" Rails::TestTask.new(:all) do |t| t.pattern = "test/**/*_test.rb" end 

https://github.com/rails/rails/blob/v4.2.7.1/railties/lib/rails/test_unit/testing.rake#L24-L27

Rails在这里使用Rails :: TestTask作为test:all目标,它将加载所有测试文件。

 def define task @name do if ENV['TESTOPTS'] ARGV.replace Shellwords.split ENV['TESTOPTS'] end libs = @libs - $LOAD_PATH $LOAD_PATH.unshift(*libs) file_list.each { |fl| FileList[fl].to_a.each { |f| require File.expand_path f } } end end 

https://github.com/rails/rails/blob/v4.2.7.1/railties/lib/rails/test_unit/sub_test_task.rb#L106-L118

但是与Rake :: TestTask立即运行测试不同,Rails :: TestTask只需要运行测试所需的文件,然后依靠Minitest中的at_exit处理程序运行测试。 这意味着对于运行测试,rake依赖关系将被完全忽略。

我更新了到源代码的链接,因为讨论是关于Rails 4.1.8的,但是问题仍然存在于Rails 4.2.7.1的源代码中。

此问题已报告 GitHub上的Rails团队 ,已在此PR中修复。

也就是说:从Rails 5.0.0起应该解决此问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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