2011-03-24 77 views
12

我對存在於幾個不同市場的網站產品進行RSpec測試。每個市場都有不同的功能組合等。我希望能夠編寫測試,以便在運行時跳過自己,具體取決於它們所針對的市場/環境。在不同的市場中運行測試不應該失敗,也不應該通過 - 它們根本不適用。在運行時跳過RSpec測試用例

不幸的是,似乎沒有簡單的方法將測試標記爲跳過。我怎麼會去這樣做,但不嘗試注入「待定」塊(這是不準確的呢?)

回答

17

使用exclusion filters

describe "market a", :market => 'a' do 
    ... 
end 
describe "market b", :market => 'b' do 
    ... 
end 
describe "market c", :market => 'c' do 
    ... 
end 

RSpec.configure do |c| 
    # Set these up programmatically; 
    # I'm not sure how you're defining which market is 'active' 
    c.filter_run_excluding :market => 'a' 
    c.filter_run_excluding :market => 'b' 
    # Now only tests with ":market => 'c'" will run. 
end 

或者更好的是,使用implicit filters

describe "market a", :if => CurrentMarket.a? do # or whatever 
    ... 
end 
+0

隱式過濾器似乎是要走的路。我很驚訝,測試沒有辦法向格式化程序報告它被排除在外:/ – andrewdotnich 2011-03-24 22:53:23

相關問題