2013-12-22 81 views
0

我創建了一個寶石項目,並添加MINITEST和保護的依賴關係:護MINITEST沒有找到測試執行當被測課改

spec.add_development_dependency "minitest", "~> 5.0.7" 
    spec.add_development_dependency 'guard-minitest' 

我使用MINITEST規格所以在測試中所有的代碼位於lib目錄中,並且所有測試都在spec中。

我創建了一個Guardfile與相應的設置:

guard :minitest do 
    # with Minitest::Spec 
    watch(%r{^spec/(.*)_spec\.rb}) 
    watch(%r{^lib/(.+)\.rb})   { |m| "spec/#{m[1]}_spec.rb" } 
    watch(%r{^spec/spec_helper\.rb}) { 'spec' } 
end 

每次我修改規範(比如spec/shell/remote_shell_spec.rb)測試正確執行。

# Running: 

....... 

Fabulous run in 0.064205s, 109.0261 runs/s, 529.5554 assertions/s. 

7 runs, 34 assertions, 0 failures, 0 errors, 0 skips 

的問題是,當我在測試修改代碼(比如lib/shell/remote_shell.rb)後衛檢測的變化,但不執行測試:

# Running: 



Finished in 0.000824s, 0.0000 runs/s, 0.0000 assertions/s. 

0 runs, 0 assertions, 0 failures, 0 errors, 0 skips 
+0

這看起來不錯。你確定你沒有任何錯別字嗎? '%r {^ lib /(。+)\。rb}'將匹配'lib/shell/remote_shell.rb',捕獲組將會是'shell/remote_shell',將被轉換爲'spec/shell/remote_shell_spec .rb'。 – Netzpirat

+0

我直接從Guardfile複製/粘貼代碼。我也讓Guardfile輸出'm [1]'的值到一個文件中。看起來是正確的('shell/remote_shell')。 – Jef

+0

源代碼可在這裏找到:https://github.com/servebox/electric_sheeps – Jef

回答

2

在您的鏈接的源代碼看,我看你的代碼被放置在lib/electric_sheeps/shell/remote_shell.rb中,而不是如lib/shell/remote_shell.rb所示,因此您的規範必須放置在spec/electric_sheeps/shell/remote_shell_spec.rb中,以便映射工作。

你也可以重寫觀察者因此會忽略模塊文件夾

guard :minitest do 
    # with Minitest::Spec 
    watch(%r{^spec/(.*)_spec\.rb}) 
    watch(%r{^lib/electric_sheeps/(.+)\.rb})   { |m| "spec/#{m[1]}_spec.rb" } 
    watch(%r{^spec/spec_helper\.rb}) { 'spec' } 
end 

但後來lib/electric_sheeps.rb映射是行不通的。

+0

現在似乎很明顯......謝謝! – Jef