2011-09-29 78 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中出現(如你不)。