Skip to Content

Rspec - specific_specs options

Posted on

Sometime, we need to do something different in some specific test cases.

It’s reason why rspec supports option specific_specs.

For example:

before(:each, specific_specs: true) do
  puts "before hook runs"
end

it 'wont run the before hook' do
  true
end

it 'will run the before hook', specific_specs: true do
  true
end

The code below is full version for this example:

describe("something", specific_specs: true) do
  before(:each, specific_specs: true) do
    puts "before hook runs"
  end

  it 'wont run the before hook', specific_specs: false do
    true
  end

  it 'will run the before hook' do
    true
  end
end

Or if you want to convert specific_specs position, you could try:

describe("something", specific_specs: false) do
  before(:each, specific_specs: false) do
    puts "before hook runs"
  end

  it 'will run the before hook' do
    true
  end

  it 'wont run the before hook', specific_specs: true do
    true
  end
end

Reference: https://github.com/rspec/rspec-core/issues/1200

comments powered by Disqus