在运行时跳过 RSpec 测试用例
我正在针对多个不同市场中存在的网站产品运行 RSpec 测试。每个市场都有细微不同的功能组合等。我希望能够编写测试,以便它们在运行时根据它们所针对的市场/环境跳过自己。当在不同的市场运行时,测试不应该失败,也不应该通过——它们根本不适用。
不幸的是,似乎没有一种简单的方法可以将测试标记为已跳过。我将如何在不尝试注入“待处理”块(无论如何都不准确?)的情况下执行此操作?
I'm running RSpec tests against a website product that exists in several different markets. Each market has subtly different combinations of features, etc. I would like to be able to write tests such that they skip themselves at runtime depending on which market/environment they are being run against. The tests should not fail when run in a different market, nor should they pass -- they're simply not applicable.
Unfortunately, there does not seem to be an easy way to mark a test as skipped. How would I go about doing this without trying to inject "pending" blocks (which aren't accurate anyway?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用排除过滤器。
或者更好的是,使用隐式过滤器 。
Use exclusion filters.
Or better still, use implicit filters.
我发现这个问题正在寻找一种方法来真正跳过我知道现在会失败的示例,但我想在情况发生变化后“取消跳过”它们。因此,对于 rspec 3.8,我发现可以在示例中使用
skip
就像这样:实际上,在大多数情况下(可能不像这个问题那么复杂)我宁愿使用
pending
> 而不是skip
,因为如果测试停止失败它会通知我,这样我就可以“取消跳过”它们。众所周知,跳过的测试将永远不会再执行 =)I spotted this question looking for a way to really skip examples that I know are going to fail now, but I want to "unskip" them once the situation's changed. So for rspec 3.8 I found one could use
skip
inside an example just like this:Actually, in most situations (maybe not as complicated as in this question) I would rather use
pending
instead ofskip
, 'cause it will notify me if tests stop failing, so I can "unskip" them. As we all know that skipped tests will never be performed ever again =)