Rspec-core: Possible to exclude particular examples?

Created on 4 Jun 2016  ·  5Comments  ·  Source: rspec/rspec-core

Hi,

I've been packaging a few rubygems for GNU Guix, and one thing I'd occasionally like to do is disable specific examples. I guess the opposite of the rspec --example flag. This is useful when e.g. certain tests might be known failures, because the automated build system requires a zero exitstatus when running the 'check' phase (to indicate that all tests pass).

Workarounds exist e.g. patching the test files but it would make life easier if we could ask rspec to do it for us. Is there some way of doing this already or is this issue a feature request?

Thanks,
ben

Most helpful comment

I think it would be reasonable to add --exclude-example.

All 5 comments

Perhaps I am being slow but I cannot see how any of those links help. Perhaps an example might help clear things up. For instance if I have this spec:

$ cat ~/t/a.spec
require 'rspec'

class My
  def self.answer
    4
  end
end

RSpec.describe My, "#answer" do
  context 'good and bad' do
    it 'gives the right answer' do
      expect(My.answer).to eq 4
    end
    it 'gives the wrong answer' do
      expect(My.answer).to eq -1
    end
  end
end

Then how do I run something that achieves the following?

$ rspec ~/t/a.spec --exclude-example wrong

I'm looking for a way that doesn't involve modifying the spec file itself.

Thanks.

RSpec.describe "My#answer" do
  context 'good and bad' do
    it 'gives the right answer', type: :right do
      expect(My.answer).to eq 4
    end
    it 'gives the wrong answer', type: :wrong do
      expect(My.answer).to eq -1
    end
  end
end

$ rspec ~/t/a.spec --tag @right or $ rspec ~/t/a.spec --tag ~@wrong

You added type: wrong. Do I take it from your answer that it is not possible to achieve something similar without modifying the spec, making this issue a feature request?

I think it would be reasonable to add --exclude-example.

Was this page helpful?
0 / 5 - 0 ratings