Ruby:如何在1.9.3中将选项传递给test :: unit

时间:2011-09-29 17:25:54

标签: ruby testunit ruby-1.9 ruby-1.9.3

我想运行一个测试文件:

# xxx.rb
require 'test/unit'; class XTest < Test::Unit::TestCase; def test_xxx; end; end

直到红宝石1.9.2

ruby -Itest -e "require './xxx.rb'" - -v

完成了这项工作,我突然得到了1.9.3:

/usr/local/rvm/rubies/ruby-1.9.3-rc1/lib/ruby/1.9.1/test/unit.rb:167:in
`block in non_options': file not found: - (ArgumentError)

(它试图加载' - '不存在的文件)

有关如何获取详细模式/将选项传递给test :: unit的任何想法吗?

正确的输出如下:

Loaded suite -e
Started
test_xxx(XTest): .

1 个答案:

答案 0 :(得分:1)

使用双击法尝试:

ruby -Itest -e "require './xxx.rb'" -- -v

或者像这样(没有破折号,没有要求):

ruby -Itest xxx.rb -v

为了解释,我认为在您的示例中,您使用的是单个破折号,通常意味着“将stdin用作文件”。你可以这样做,例如:

cat xxx.rb | ruby -Itest - -v

双短划线用于停止参数解析,因此将-v传递给测试单元。至于为什么你的单个破折号的例子达到了1.9.3 ...我猜测在1.9.3之前ruby并没有像你指定stdin那样严格但是没有任何东西进入stdin(如你没有。)