Pending and Skipped Examples

Pending and skipped examples

Sometimes you will have a failing example that can not be fixed, but is useful to keep around. For instance, the fix could depend on an upstream patch being merged, or the example is not supported on JRuby. RSpec provides two features for dealing with this scenario.

An example can either be marked as skipped, in which is it not executed, or pending in which it is executed but failure will not cause a failure of the entire suite. When a pending example passes (i.e. the underlying reasons for it being marked pending is no longer present) it will be marked as failed in order to communicate to you that it should no longer be marked as pending.

`pending` examples

RSpec offers a number of different ways to indicate that an example is
disabled pending some action.Scenarios

  1. `pending` any arbitrary reason with a failing example
  2. `pending` any arbitrary reason with a passing example
  3. `pending` for an example that is currently passing
  4. `pending` for an example that is currently passing with a reason

`pending` any arbitrary reason with a failing exampleGivena file named “pending_without_block_spec.rb” with:

RSpec.describe "an example" do
  it "is implemented but waiting" do
    pending("something else getting finished")
    fail
  end
end

WhenI run rspec pending_without_block_spec.rbThenthe exit status should be 0Andthe output should contain “1 example, 0 failures, 1 pending”Andthe output should contain:

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) an example is implemented but waiting
     # something else getting finished

`pending` any arbitrary reason with a passing exampleGivena file named “pending_with_passing_example_spec.rb” with:

RSpec.describe "an example" do
  it "is implemented but waiting" do
    pending("something else getting finished")
    expect(1).to be(1)
  end
end

WhenI run rspec pending_with_passing_example_spec.rbThenthe exit status should not be 0Andthe output should contain “1 example, 1 failure”Andthe output should contain “FIXED”Andthe output should contain “Expected pending ‘something else getting finished’ to fail. No Error was raised.”Andthe output should contain “pending_with_passing_example_spec.rb:2”`pending` for an example that is currently passingGivena file named “pending_with_passing_block_spec.rb” with:

RSpec.describe "an example" do
  pending("something else getting finished") do
    expect(1).to eq(1)
  end
end

WhenI run rspec pending_with_passing_block_spec.rbThenthe exit status should not be 0Andthe output should contain “1 example, 1 failure”Andthe output should contain “FIXED”Andthe output should contain “Expected pending ‘No reason given’ to fail. No Error was raised.”Andthe output should contain “pending_with_passing_block_spec.rb:2”`pending` for an example that is currently passing with a reasonGivena file named “pending_with_passing_block_spec.rb” with:

RSpec.describe "an example" do
  example("something else getting finished", :pending => 'unimplemented') do
    expect(1).to eq(1)
  end
end

WhenI runĀ rspec pending_with_passing_block_spec.rbThenthe exit status should not be 0Andthe output should contain “1 example, 1 failure”Andthe output should contain “FIXED”Andthe output should contain “Expected pending ‘unimplemented’ to fail. No Error was raised.”Andthe output should contain “pending_with_passing_block_spec.rb:2”

`skip` examples

RSpec offers a number of ways to indicate that an example should be skipped
and not executed.Scenarios

  1. No implementation provided
  2. Skipping using `skip`
  3. Skipping using `skip` inside an example
  4. Temporarily skipping by prefixing `it`, `specify`, or `example` with an x
  5. Skipping using metadata

No implementation providedGivena file named “example_without_block_spec.rb” with:

RSpec.describe "an example" do
  it "is a skipped example"
end

WhenI run rspec example_without_block_spec.rbThenthe exit status should be 0Andthe output should contain “1 example, 0 failures, 1 pending”Andthe output should contain “Not yet implemented”Andthe output should contain “example_without_block_spec.rb:2”Skipping using `skip`Givena file named “skipped_spec.rb” with:

RSpec.describe "an example" do
  skip "is skipped" do
  end
end

WhenI run rspec skipped_spec.rbThenthe exit status should be 0Andthe output should contain “1 example, 0 failures, 1 pending”Andthe output should contain:

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) an example is skipped
     # No reason given
     # ./skipped_spec.rb:2

Skipping using `skip` inside an exampleGivena file named “skipped_spec.rb” with:

RSpec.describe "an example" do
  it "is skipped" do
    skip
  end
end

WhenI run rspec skipped_spec.rbThenthe exit status should be 0Andthe output should contain “1 example, 0 failures, 1 pending”Andthe output should contain:

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) an example is skipped
     # No reason given
     # ./skipped_spec.rb:2

Temporarily skipping by prefixing `it`, `specify`, or `example` with an xGivena file named “temporarily_skipped_spec.rb” with:

RSpec.describe "an example" do
  xit "is skipped using xit" do
  end

  xspecify "is skipped using xspecify" do
  end

  xexample "is skipped using xexample" do
  end
end

WhenI run rspec temporarily_skipped_spec.rbThenthe exit status should be 0Andthe output should contain “3 examples, 0 failures, 3 pending”Andthe output should contain:

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) an example is skipped using xit
     # Temporarily skipped with xit
     # ./temporarily_skipped_spec.rb:2

  2) an example is skipped using xspecify
     # Temporarily skipped with xspecify
     # ./temporarily_skipped_spec.rb:5

  3) an example is skipped using xexample
     # Temporarily skipped with xexample
     # ./temporarily_skipped_spec.rb:8

Skipping using metadataGivena file named “skipped_spec.rb” with:

RSpec.describe "an example" do
  example "is skipped", :skip => true do
  end
end

WhenI run rspec skipped_spec.rbThenthe exit status should be 0Andthe output should contain “1 example, 0 failures, 1 pending”Andthe output should contain:

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) an example is skipped
     # No reason given
     # ./skipped_spec.rb:2

Last published almost 5 years ago by myronmarston.