在运行时跳过 RSpec 测试用例

发布于 2024-10-26 12:29:17 字数 200 浏览 2 评论 0原文

我正在针对多个不同市场中存在的网站产品运行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

回首观望 2024-11-02 12:29:17

使用排除过滤器

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

或者更好的是,使用隐式过滤器

describe "market a", :if => CurrentMarket.a? do # or whatever
   ...
end

Use 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

Or better still, use implicit filters.

describe "market a", :if => CurrentMarket.a? do # or whatever
   ...
end
万劫不复 2024-11-02 12:29:17

我发现这个问题正在寻找一种方法来真正跳过我知道现在会失败的示例,但我想在情况发生变化后“取消跳过”它们。因此,对于 rspec 3.8,我发现可以在示例中使用 skip 就像这样:

it 'is going to fail under several circumstances' do
  skip("Here's the reason") if conditions_met?
  expect(something)
end

实际上,在大多数情况下(可能不像这个问题那么复杂)我宁愿使用 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:

it 'is going to fail under several circumstances' do
  skip("Here's the reason") if conditions_met?
  expect(something)
end

Actually, in most situations (maybe not as complicated as in this question) I would rather use pending instead of skip, '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 =)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文