Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable a group of tests in rspec?

Tags:

ruby

rspec

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

Is there a way I can disable a context temporarily?

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.

This is what I kind of had:

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.

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?

like image 666
Jorge Israel Peña Avatar asked May 07 '11 01:05

Jorge Israel Peña


2 Answers

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

before { skip } # or  xdescribe # or  xcontext 

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

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

with RSpec 2:

before { pending } 
like image 178
Pyro Avatar answered Sep 20 '22 01:09

Pyro


Use exclusion filters. From that page: In your 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 "group 2 example 1"

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

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

like image 45
Robert Speicher Avatar answered Sep 22 '22 01:09

Robert Speicher