0

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

我的 testA.rb :

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

Begin of the code...
... End of the code

通常我使用以下 cmd 执行测试:

ruby -I E:/pathToIncludeA/includeA.rb -I E:/pathToIncludeB/includeB.rb -I E:/pathToIncludeC/includeC.rb -I E:/pathToIncludeD/includeD.rb E:/pathToTestA.rb/testA.rb

一切正常。

但是现在我正在使用 rake,并且我正在尝试以相同的方式包含目录。

这是我的 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
  ruby '-I E:/pathToIncludeA/includeA.rb', '-I E:/pathToIncludeB/includeB.rb, '-I E:/pathToIncludeC/includeC.rb', '-I E:/pathToIncludeD/includeD.rb', E:/pathToTestA.rb/testA.rb
end

但是当我执行以下 cmd 时:

rake test

我有以下错误:

E:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in 'gem_original_require': no such file to load -- includeA.rb (load error)
from E:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in 'require'
from E:/pathToTestA/testA.rb/

rake aborted!
command failed with status (1): [E:/Ruby/bin/ruby.exe -I pathToIncludeA/...]
Tasks: TOP => default => test

我做错了什么?有人可以帮助我吗?

4

1 回答 1

1

试试这个:

task :test do
  sh "ruby -I E:/pathToIncludeA/includeA.rb -I E:/pathToIncludeB/includeB.rb -I E:/pathToIncludeC/includeC.rb -I E:/pathToIncludeD/includeD.rb E:/pathToTestA.rb/testA.rb"
end

或者,如果您需要/喜欢ruby在任务中使用该方法,请更改您testA.rb的加载路径include(A|B|C|D).rb,然后:

task :test do
  # assuming the Rakefile and the testA.rb are in the same folder.
  ruby "testA.rb"
end

如果您的测试套件包含多个测试文件testA.rb,例如testB.rb等,那么Rake::TestTask该类可能会使它变得更容易。检查 Sinatra 项目如何使用它来获得一个想法:Sinatra/RakefileRake::TestTask文档

于 2013-04-03T11:11:14.297 回答