【问题标题】:Ruby: How to pass options to test::unit in 1.9.3Ruby:如何在 1.9.3 中将选项传递给 test::unit
【发布时间】:2011-09-29 17:25:53
【问题描述】:

我想运行一个测试文件:

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

直到 ruby​​ 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): .

【问题讨论】:

    标签: ruby testunit ruby-1.9 ruby-1.9.3


    【解决方案1】:

    用双破折号试试:

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

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

    ruby -Itest xxx.rb -v
    

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

    cat xxx.rb | ruby -Itest - -v
    

    双破折号用于停止参数解析,因此将 -v 传递给测试单元。至于为什么您的带有单个破折号的示例可以达到 1.9.3... 我猜在 1.9.3 之前,当您指定标准输入但没有任何内容进入标准输入时,ruby 并没有那么严格(如你没有)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-16
      • 2011-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-29
      • 1970-01-01
      相关资源
      最近更新 更多