2013-02-23 104 views
1

我使用這個命令來運行一些測試...爲什麼Ruby只運行一些測試而不運行其他測試?

bundle exec ruby -Itest test/functional/*.rb 

在我test/functional DIR我有兩個文件...

file_sets_controller_test.rb 
user_sessions_controller_test.rb 

通過上面的命令,在file_sets_controller_test.rb所有測試運行但user_sessions_controller_test.rb中的那些根本不運行 - 不報告錯誤或其他輸出。

不過,我可以直接運行該文件沒有問題,這... ...

bundle exec ruby -Itest test/functional/user_sessions_controller_test.rb 

這工作正常。

我知道另一種選擇是使用rake test functionals,但與直接運行它相比,速度非常慢。


ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin11.4.2] 

Rails 3.2.12 

這裏是我的Gemfile的一部分...

group :development, :test do 

    gem 'ansi' 
    gem 'turn' 

    gem 'minitest' 
    gem 'minitest-matchers' 

end 

這是我的test_helper.rb ...

ENV["RAILS_ENV"] = "test" 
require File.expand_path('../../config/environment', __FILE__) 
require 'rails/test_help' 

require 'turn/autorun' 
Turn.config.ansi = true 

require 'minitest/autorun' 

class ActiveSupport::TestCase 

    fixtures :all 

end 

卸下轉向與MINITEST寶石沒有按據我所知,沒有任何改變。

+0

你知道'耙測試:functionals',對不對? – 2013-02-23 09:17:56

回答

7

ruby命令會將ruby文件作爲第一個參數運行,並使其他參數可用於ruby程序。 shell將您的glob表達式擴展爲2個參數並將它們傳遞給ruby,因此ruby正在擴展中運行第一個文件名。

附加:

我認爲你可以做你想做什麼喜歡的東西......

bundle exec ruby -Itest -e "Dir.glob('test/functional/*_test.rb').each{|f| require File.expand_path(f)}" 
+0

對嗎?當我運行測試時(在老版本的Rails中),該命令始終將所有文件都視爲** 1 **字符串,文件在字符串中用空格分隔。 – 244an 2013-02-23 03:40:24

+0

哎呀,這是我的錯誤,哈哈! Steve&244an我欠你一杯啤酒。史蒂夫,如果你編輯你的答案有點我可以改變我的downvote upvote。 (該命令適用於我的設置,因爲我的代碼攔截了glob)。 – joelparkerhenderson 2013-02-23 05:21:48

+0

@joelparkerhenderson我不清楚你的建議是什麼編輯。你能澄清嗎? – 2013-02-23 05:34:58

相關問題