Disable test group in rspec?

I have a test specification in which the class is describes and inside which there are different contexts , each with different it blocks.

Is there a way to temporarily disable context ?

I tried to add the pending "temporarily disabled" call to the very top inside the context that I want to disable, and I saw something in anticipation when I ran the spec, but then it just continued to run the rest of the tests.

This is what I kind of like:

 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, as I said, he just continued the tests under a waiting call.

A search led me to this mailing list list in which the creator (?) Rspec says this is possible in rspec 2, m works. I think this worked, but it did not have the desired effect of disabling all of the following tests, which I think of when I see the pending call.

Is there an alternative, or am I doing it wrong?

+83
ruby rspec bdd
May 7 '11 at 1:46
source share
7 answers

To disable the specification tree using RSpec 3 , you can:

 before { skip } # or xdescribe # or xcontext 

You can add a skipped message that will be displayed on the output:

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

with RSpec 2 :

 before { pending } 
+125
Oct 04
source share

Use exception filters . From this page: In spec_helper.rb (or rails_helper.rb )

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

In your test:

 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 

When I run "rspec./spec/sample_spec.rb --format doc"

Then the output should contain "example 2 of group 2"

And the output should not contain "example 1 group 1"

And the output should not contain "example 1 group 1"

+41
May 7, '11 at 1:57
source share

See what you think about it:

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

I like to see the reasons with my pending items when I turn off something โ€œfor a whileโ€. They serve as small comments / TODOs that are presented regularly, and not buried in a comment or excluded example / file.

Changing it to pending or xit is quick and easy, but I prefer the hash design. It gives you all the documentation, itโ€™s drop-down (does not change the description / context / itโ€™s so, I have to decide what to use later) and is just as easily deleted if the decision is made or the blocker is deleted.

This works the same for groups and individual examples.

+15
May 01 '14 at 15:03
source share

other. https://gist.github.com/1300152

use xdescribe, xcontext, xit to disable it.

Update:

Since rspec 2.11, by default it includes xit. so the new code will be

 # 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 

Using

 # a_spec.rb xdescribe "padding" do it "returns true" do 1.should == 1 end end 
+8
Oct. 20 '11 at 1:13
source share

Use pending instead of description. If your unit:

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

You can skip the whole block:

 pending "some other tests" do it "should do something destructive" do blah end end 
+3
Mar 17 '13 at 17:13
source share
 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 
+1
Oct 31 '13 at 3:39 on
source share

Just to explain what happens to your code. By including it wherever you have it, it just gets an estimate (and therefore runs) when the file is downloaded at launch time. However, you need it to start when you run the tests. Therefore, the answers suggested putting pending (RSpec 2) or skip (RSpec 3) in the before block.

0
Jan 16 '15 at 7:56
source share



All Articles