can I use multiple exclusion filters in rspec?

谁说我不能喝 提交于 2019-12-22 10:50:49

问题


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.


回答1:


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

Try this out and this works.



来源:https://stackoverflow.com/questions/5628880/can-i-use-multiple-exclusion-filters-in-rspec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!