rubyspecifications

Programmatically skip a test in RSpec


I am curious if there is a way to skip a test in RSpec in a before block? I am thinking something like this:

RSpec.configure do |config|
  config.before(:each) do |spec|
    if some_condition?
      spec.skip
    end
  end
end

The above call to skip does not work. This is for an idea I am working on, so it's important that it works this way and not have to modify the test with metadata for instance. I imagine it's possible using RSpec internals, for instance tagging the status, but I wanted to check first to see if there is any API for this.


Solution

  • I asked in the rspec mailing list, and it turns out skip 'reason' does the trick. The example is marked as pending, which is not ideal, but that answers the question.