Ruby – Disable a group of tests in rspec

rspecruby

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?

Best Answer

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 }
Related Topic