在 rspec 中禁用一组测试? [英] Disable a group of tests in rspec?

查看:21
本文介绍了在 rspec 中禁用一组测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个测试规范,它描述一个类,其中有各种上下文,每个都有各种it块.

I have a test spec which describes a class and within that has various contexts each with various it blocks.

有什么办法可以暂时禁用context?

Is there a way I can disable a context temporarily?

我尝试在我想禁用的 context 的最顶部添加一个 pending "temporously disabled" 调用,当我运行规范,然后它只是继续运行其余的测试.

I tried adding a pending "temporarily disabled" call at the very top within a context I want to disable, and I did see something about pending when I ran the spec but then it just continued to run the rest of the tests.

这就是我所拥有的:

describe Something
  context "some tests" do
    it "should blah" do
      true
    end
  end

  context "some other tests" do
    pending "temporarily disabled"

    it "should do something destructive" do
      blah
    end
  end
end

但就像我说的那样,它只是继续在挂起的调用下运行测试.

but like I said it just went on to run the tests underneath the pending call.

搜索让我找到了这个邮件列表主题其中 rspec 的创建者 (?) 说在我正在运行的 rspec 2 中是可能的.我想它确实有效,但它没有禁用以下所有测试的预期效果,这就是我看到 pending 调用时的想法.

Searching led me to this mailing list thread in which the the creator (?) of rspec says it's possible in rspec 2, which I'm running. I guess it did work but it didn't have the desired effect of disabling all of the following tests, which is what I think of when I see a pending call.

有没有其他选择,还是我做错了?

Is there an alternative or am I doing it wrong?

推荐答案

要使用 RSpec 3 禁用规范树,您可以:

To disable a tree of specs using RSpec 3 you can:

before { skip }
# or 
xdescribe
# or 
xcontext

您可以使用 skip 添加将显示在输出中的消息:

You can add a message with skip that will show up in the output:

before { skip("Awaiting a fix in the gem") }

使用RSpec 2:

before { pending }

这篇关于在 rspec 中禁用一组测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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