开发者

How do I get file name of the file currently being tested by rake

开发者 https://www.devze.com 2023-01-26 03:45 出处:网络
In my rake task if I want to know the开发者_运维知识库 name of the file when that file is picked up for testing then how do I do that. Reason is that some of the files produce warning. I am not sure w

In my rake task if I want to know the开发者_运维知识库 name of the file when that file is picked up for testing then how do I do that. Reason is that some of the files produce warning. I am not sure which of my 800 tests is producing warning.

My rake task is something like this. I am using rails3.

Rake::TestTask.new(:test_hr_module) do |t|
  t.libs << 'test'

  t.test_files = Dir.glob('test/{hr}/**/*_test.rb').sort

  t.warning = true
  t.verbose = true
end


You can always call single files:

ruby test/unit/model_test.rb

You can even use the name flag to only run specific tests

ruby test/unit/model_test.rb -n test_name

You'll probably need to change require 'test_helper' to require 'test/test_helper' in the test file though.

If you really need to do this in a rake task could you try:

Dir.glob('test/**/*_test.rb').each do |f|
  puts `ruby #{f}`
end

end


Perhaps you can use the pseudo-variable __FILE__ to achieve this?

0

精彩评论

暂无评论...
验证码 换一张
取 消