rspec / rspec-core

RSpec runner and formatters
http://rspec.info
MIT License
1.23k stars 765 forks source link

when_first_matching_example_defined should not run for dry run #2971

Closed ngan closed 1 year ago

ngan commented 2 years ago

Subject of the issue

I would have expected when_first_matching_example_defined to not execute when running with --dry-run. It feels in the spirit of:

Use the --dry-run option to have RSpec print your suite's formatter output without running any examples or hooks.

Your environment

Steps to reproduce

RSpec.configure do |config|
  config.when_first_matching_example_defined(type: :model) do
    puts "This should not print"
  end
end

RSpec.describe MyModel do
  it "foobar" do
    fail
  end
end
rspec --dry-run spec/models/my_model_spec.rb

Expected behavior

I should not see "This should not print"

Actual behavior

I see "This should not print"

ngan commented 1 year ago

Closing this because according to this, the when_first_matching_example_defined hook executes when an example is detected on load of the test suite, not when the first example matching the filter is run.