2011-03-24 75 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

相关问题