2010-10-23 63 views
2

這應該很簡單,但我找不到任何示例。我在我的軌道,看起來就像標準的功能測試3個應用程序(從ActionController的TestCase的::降序):Rails功能測試 - 從設置中排除方法

test "see if 1+1=2" do 
.... 
end 

,並在上面我有一個設置方法:

setup do 
    ...... 
end 

如何排除一個方法?即

setup :except => "see if 1+1=2" do 
... 
end 

(以上不工作OBV)

回答

0

使用shoulda和上下文塊,這樣你可以把使用安裝測試在一個範圍內,並且測試不使用它們在另一個,或外部另一個上下文塊。

0

我也很好奇。無需安裝和學習任何新的寶石一種解決方法。將你的測試中定義一個私有函數

test "see if 1+1=2" do 
    setup_situation_1 
    ... 
end 

test "see if 1 * 1 = 1" do 
    setup_situation_1 
    .. 
end 

test "see if 1/1 = 1" do 
    # no setup here 
    ... 
end 

... 

private 
def setup_situation_1 
    ... 
end 

這是DRY-EST方法,我能想到的,而無需安裝/學習新的寶石 - 這可能是一個對於一些人來說,這是最好的解決方案,特別是那些新的鐵路。但是,我找不到這個setup/do方法的文檔 - setup/do的「except」子句肯定是DRY-er。