可以在rspec中使用多个排除过滤器吗? [英] can I use multiple exclusion filters in rspec?

查看:78
本文介绍了可以在rspec中使用多个排除过滤器吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在_spec.rb文件中,我正在设置排除过滤器,例如:

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

然后再在文件中完成

describe :get_items_by_client, :svr1 => :available do

如果服务器不可用,则阻止测试执行.

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

如果我仅运行规格文件,那么一切都可以正常工作.但是,我在另一个文件中也有类似的代码,这些文件控制着访问不同服务器的测试,并且当我运行所有文件时,我只能看到每个服务器检查都已完成(我在"serverX_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

尝试一下,这个方法就可以了.

Try this out and this works.

这篇关于可以在rspec中使用多个排除过滤器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆