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

Ruby:如何将选项传递给1.9.3中的test::unit,ruby,testunit,ruby-1.9,ruby-1.9.3,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.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: - (ArgumentErro

我想运行一个测试文件:

# xxx.rb
require 'test/unit'; class XTest < Test::Unit::TestCase; def test_xxx; end; end
完成了任务,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): .

用双破折号试一试:

ruby -Itest -e "require './xxx.rb'" -- -v
或者像这样(没有破折号,没有要求):

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

cat xxx.rb | ruby -Itest - -v

双破折号用于停止参数解析,从而将-v传递给测试单元。至于为什么你用一个破折号的例子可以达到1.9.3。。。我猜在1.9.3之前,ruby在指定stdin时没有那么严格,但在stdin中没有任何内容(你没有)。请用双破折号试试:

ruby -Itest -e "require './xxx.rb'" -- -v
或者像这样(没有破折号,没有要求):

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

cat xxx.rb | ruby -Itest - -v
双破折号用于停止参数解析,从而将-v传递给测试单元。至于为什么你用一个破折号的例子可以达到1.9.3。。。我猜在1.9.3之前,ruby在指定stdin时没有那么严格,但是在stdin上没有任何东西(你没有)