2011-09-29 108 views
1

测试::单位我想运行一个测试文件:红宝石:如何通过选项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?

正确的输出将如下所示:

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

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

ruby -Itest xxx.rb -v 

Loaded suite -e 
Started 
test_xxx(XTest): . 

回答

1

与双破折号试试吧为了解释,我认为在你的例子中你使用了一个单独的短划线,通常意味着'使用stdin作为文件'。你可以这样做,例如:

cat xxx.rb | ruby -Itest - -v 

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