【问题标题】:How to run all ruby files in specified directory with rake如何使用 rake 运行指定目录中的所有 ruby​​ 文件
【发布时间】:2013-03-30 15:01:37
【问题描述】:

我已经安装了 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

这是我的 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

然后我启动测试执行:

rake CI_REPORTER=reports test

一切正常,但现在我的“pathToTest”中将添加很多测试,现在我想运行所有测试,但在我的 rakefile 中使用一个 cmd。

我从 Windows 批处理 cmd 尝试这个:for /r "E:\ExempleOfTests\" %%i in (*.rb) do ruby "%%i"

它运行文件夹 ExempleOfTests 中的所有 .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 "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”启动时我的输出控制台:

unexpected %%i
rake aborted
commande failed with status (1) ...

有人可以帮我吗?

【问题讨论】:

    标签: ruby testing directory rake


    【解决方案1】:

    你可以这样运行它:

    find path/to/test/folder -name '*_test.rb' | xargs -n1 -I{} bundle exec ruby -Itest {}
    

    然后根据需要将其包装到 rake 任务中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-15
      • 2017-04-19
      • 1970-01-01
      • 2015-08-20
      • 2011-02-04
      • 1970-01-01
      • 1970-01-01
      • 2014-12-04
      相关资源
      最近更新 更多