如何使用rake在指定目录下运行所有ruby文件

如何使用rake在指定目录下运行所有ruby文件,ruby,testing,directory,rake,Ruby,Testing,Directory,Rake,我已经安装了Ruby 1.8.7、ci_reporter 1.8.4、测试单元2.5.4、rake 10.0.3 我的testA.rb,testB.rb。。。testZ.rb: require 'includeA.rb' require 'includeB.rb' require 'includeC.rb' require 'includeD.rb' Begin of the code... ... End of the code 这是我的耙子: require 'rake/testtask

我已经安装了Ruby 1.8.7、ci_reporter 1.8.4、测试单元2.5.4、rake 10.0.3

我的testA.rb,testB.rb。。。testZ.rb:

require 'includeA.rb'
require 'includeB.rb'
require 'includeC.rb'
require 'includeD.rb'

Begin of the code...
... End of the code
这是我的耙子:

require 'rake/testtask'
require 'rubygems'
gem 'ci_reporter'
gem 'test-unit' 
require 'test/unit' 
require 'ci/reporter/rake/test_unit'  

task :default => [:test]

task :test do
  sh "ruby -I E:/pathToIncludesA/" " -I E:/pathToIncludesB/" " -I E:/pathToIncludesC/" " -I E:/pathToIncludesD/" " E:/pathToTests/testA.rb"
  sh "ruby -I E:/pathToIncludesA/" " -I E:/pathToIncludesB/" " -I E:/pathToIncludesC/" " -I E:/pathToIncludesD/" " E:/pathToTests/testB.rb"
  ...
  sh "ruby -I E:/pathToIncludesA/" " -I E:/pathToIncludesB/" " -I E:/pathToIncludesC/" " -I E:/pathToIncludesD/" " E:/pathToTests/testZ.rb"
end
require 'rake/testtask'
require 'rubygems'
gem 'ci_reporter'
gem 'test-unit' 
require 'test/unit' 
require 'ci/reporter/rake/test_unit'  

task :default => [:test]

task :test do
  sh "for /r E:/pathToTests/ %%i in (*.rb) do ruby -I E:/pathToIncludesA/ -I E:/pathToIncludesB/ -I E:/pathToIncludesC/ -I E:/pathToIncludesD/ %%i"
end
我通过以下方式启动测试执行:

rake CI_REPORTER=reports test
所有的工作都很好,但是现在很多测试将添加到我的“pathToTest”中,现在我想运行所有的测试,但是在我的rakefile中只有一个cmd

我从windows批处理cmd:
for/r“E:\exampleoftests\”%%I in(*.rb)do ruby“%%I”

它运行exampleoftests文件夹中的所有.rb文件

所以现在我正在重构我的rakefile,尝试合并windows批处理cmd

这里是我的新rakefile:

require 'rake/testtask'
require 'rubygems'
gem 'ci_reporter'
gem 'test-unit' 
require 'test/unit' 
require 'ci/reporter/rake/test_unit'  

task :default => [:test]

task :test do
  sh "ruby -I E:/pathToIncludesA/" " -I E:/pathToIncludesB/" " -I E:/pathToIncludesC/" " -I E:/pathToIncludesD/" " E:/pathToTests/testA.rb"
  sh "ruby -I E:/pathToIncludesA/" " -I E:/pathToIncludesB/" " -I E:/pathToIncludesC/" " -I E:/pathToIncludesD/" " E:/pathToTests/testB.rb"
  ...
  sh "ruby -I E:/pathToIncludesA/" " -I E:/pathToIncludesB/" " -I E:/pathToIncludesC/" " -I E:/pathToIncludesD/" " E:/pathToTests/testZ.rb"
end
require 'rake/testtask'
require 'rubygems'
gem 'ci_reporter'
gem 'test-unit' 
require 'test/unit' 
require 'ci/reporter/rake/test_unit'  

task :default => [:test]

task :test do
  sh "for /r E:/pathToTests/ %%i in (*.rb) do ruby -I E:/pathToIncludesA/ -I E:/pathToIncludesB/ -I E:/pathToIncludesC/ -I E:/pathToIncludesD/ %%i"
end
但当我使用“rake CI_REPORTS=REPORTS test”启动时,我的输出控制台:


有人能帮我吗?

您可以这样运行它:

find path/to/test/folder -name '*_test.rb' | xargs -n1 -I{} bundle exec ruby -Itest {}
然后,如果需要,将其包装到rake任务中