2010-12-01 202 views
0

我正在使用自動測試,並添加了掛鉤來運行我的集成測試。在工作時,任何時候我做出影響任何集成測試的更改,都會重新運行所有集成測試。如果可能的話,這是我想改變的行爲。 (我正在使用rspec和webrat進行我的測試,沒有黃瓜)通過自動測試運行的限制集成測試(Rails)

對於非集成測試,模式是它會在相同的spec文件(或描述塊?)中重新執行測試,或者如果更改測試或它的描述。所以說,我們有page_controller.rb和page_controller_spec.rb。 autotest知道如果你改變其中一個文件,它只運行page_controller_spec中的測試,如果它通過了,它會運行所有的測試。我想爲我的集成測試類似的東西 - 只要先運行測試失敗的測試文件,然後運行所有測試,如果他們通過。

我.autotest文件看起來像這樣

require "autotest/growl" 
require "autotest/fsevent" 

Autotest.add_hook :initialize do |autotest| 
    autotest.add_mapping(/^spec\/integration\/.*_spec\.rb$/) do 
    autotest.files_matching(/^spec\/integration\/.*_spec\.rb$/) 
    end 
end 

回答

1

.autotest是問題的根源:)這基本上說,他們對任何文件/spec/integration目錄,所有應該運行。你應該只返回匹配的文件名,像這樣:

require "autotest/growl" 
require "autotest/fsevent" 

Autotest.add_hook :initialize do |autotest| 
    autotest.add_mapping(/^spec\/integration\/.*_spec\.rb$/) do |filename| 
    filename 
    end 
end 
+0

年後,但仍然感謝你。 – 2012-04-15 16:41:58

-1

對不起,我沒有時間來完全解決您的問題,但我想你可以做你自己,當你閱讀自動測試#add_mapping的評論方法。你必須用正則表達式來玩一點。請注意「+ proc +傳遞了匹配的文件名和Regexp.last_match」。下面是完整的評論:

# Adds a file mapping, optionally prepending the mapping to the 
    # front of the list if +prepend+ is true. +regexp+ should match a 
    # file path in the codebase. +proc+ is passed a matched filename and 
    # Regexp.last_match. +proc+ should return an array of tests to run. 
    # 
    # For example, if test_helper.rb is modified, rerun all tests: 
    # 
    # at.add_mapping(/test_helper.rb/) do |f, _| 
    #  at.files_matching(/^test.*rb$/) 
    # end 

    def add_mapping regexp, prepend = false, &proc 
+0

不是很有幫助。這裏的評論容易讓人誤解,在這種情況下,他只需要返回匹配的文件名。 – szeryf 2012-04-14 14:37:44