Disable a group of tests in rspec?

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"


another one. https://gist.github.com/1300152

use xdescribe, xcontext, xit to disable it.

Update:

Since rspec 2.11, it includes xit by default. 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

Usage

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

See what you think of this:

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

I like to see reasons with my pending items when I'm disabling something for "a while". They serve as little comments/TODOs that are presented regularly rather than buried in a comment or an excluded example/file.

Changing it to pending or xit is quick and easy, but I prefer the hash construction. It gives you every-run documentation, is a drop-in (doesn't change describe/context/it so I have to decide what to use again later), and is just as easily removed if the decision is made or blocker is removed.

This works the same for groups and individual examples.


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 }

Tags:

Ruby

Rspec