在rspec中禁用一组testing?

我有一个testing规范, describes了一个类,其中有不同的contexts每个不同的块。

有没有办法可以暂时禁用context

我试图在我想禁用的context的最上面添加一个pending "temporarily disabled"调用,当我运行规范时,我确实看到了一些关于挂起的内容,但是它只是继续运行其余的testing。

这是我所拥有的:

 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 

但就像我说的那样,它只是继续在挂起的呼叫下面运行testing。

search引导我到这个邮件列表线程 ,其中rspec的创build者(?)表示在rspec 2中,我正在运行它。 我想这样做确实有效,但是它并没有达到禁用所有以下testing的效果,这是我在看到一个pending呼叫时所想到的。

有没有其他的select,或者我做错了吗?

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

 before { skip } # or xdescribe # or xcontext 

您可以添加一个消息, 跳过将显示在输出中:

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

RSpec 2

 before { pending } 

使用排除filter 。 从该页面:在您的spec_helper.rb (或rails_helper.rb

 RSpec.configure do |c| c.filter_run_excluding :broken => true end 

在你的testing中:

 describe "group 1", :broken => true do it "group 1 example 1" do end it "group 1 example 2" do end end describe "group 2" do it "group 2 example 1" do end end 

当我运行“rspec ./spec/sample_spec.rb –format doc”

那么输出应该包含“组2例1”

而输出不应该包含“组1例1”

而输出不应该包含“组1例2”

看看你对此的看法:

 describe "something sweet", pending: "Refactor the wazjub for easier frobbing" do it "does something well" it "rejects invalid input" end 

当我禁用“一段时间”的某些内容时,我希望看到有待处理项目的原因。 他们只是作为一个小小的意见/ TODO,而不是隐藏在评论或排除的例子/文件中。

it更改为pendingxit非常快捷,但我更喜欢散列结构。 它为您提供了每个运行的文档,是一个插件(不会更改describe / context /它,所以我必须稍后再决定使用什么),并且如果做出决定或阻止程序被删除。

这对于团体和个人的例子是一样的。

另一个。 https://gist.github.com/1300152

使用xdescribe,xcontext,xit来禁用它。

更新:

由于rspec 2.11,它默认包含xit。 所以新的代码将是

 # put into spec_helper.rb module RSpec module Core module DSL def xdescribe(*args, &blk) describe *args do pending end end alias xcontext xdescribe end end end 

用法

 # a_spec.rb xdescribe "padding" do it "returns true" do 1.should == 1 end end 

使用挂起而不是描述。 如果你的块是:

 context "some other tests" do it "should do something destructive" do blah end end 

你可以跳过整个块:

 pending "some other tests" do it "should do something destructive" do blah end end 
 describe "GET /blah" do before(:each) { pending "Feature to be implemented..." } it { expect(page).to have_button("Submit") } it { expect(page).to have_content("Blah") } end 

只是为了解释你的代码发生了什么。 把它包括在你所拥有的地方,只要在启动时加载文件就会被评估(并因此运行)。 但是,当testing运行时,您需要运行它。 这就是为什么答案已经build议把pending (RSpec 2)或skip (RSpec 3)放入before一个块。