can I use multiple exclusion filters in rspec?

In a _spec.rb file I'm setting up an exclusion filter something like:

RSpec.configure do |config|
  # we need determine this once at the very front
  # and the result be available in the instance
  server_success = server1_available?

  config.exclusion_filter = {
    :svr1 => lambda {|what|
      case what
      when :available
        !server_success
      end
    }
  }
end

and then later in the file I do

describe :get_items_by_client, :svr1 => :available do

to prevent test execution if the server isn't available.

This all works fine if I run the spec file alone. However, I have similar code in another file controlling tests that access a different server, and when I run them all only I see that each of the server checks is done (I have a puts in the "serverX_available?" code), but only one set of tests is being excluded (even though neither server is available).

I'm starting to think that you can have only a single exclusion filter, but I can find any docs anywhere that speak to that. Is this doable on a per-file basis? I could have a single complex filter all in a support file, but then how would I get it incorporated when I'm doing just a run of a single spec-file?

Ideally, I'd like to find a form that works per-file but let's me do the availability check once since it is a somewhat expensive check and I have several examples in the test that are controlled by that.


config.filter_run_excluding :cost => true
config.filter_run_excluding :slow => true

试试这个,这个工程。

链接地址: http://www.djcxy.com/p/59290.html

上一篇: 你如何在RSpec中运行单个测试/ spec文件?

下一篇: 我可以在rspec中使用多个排除过滤器吗?