Class: Rubocop::Cop::RSpec::FeatureSpecMaxExamples
- Inherits:
-
Base
- Object
- RuboCop::Cop::RSpec::Base
- Base
- Rubocop::Cop::RSpec::FeatureSpecMaxExamples
- Defined in:
- lib/rubocop/cop/rspec/feature_spec_max_examples.rb
Overview
Limits the number of examples in feature spec files.
Feature specs with too many examples are slow to run, hard to maintain, and often indicate the file should be split into smaller, focused specs.
The maximum number of examples can be configured with the ‘Max` option (default: 25).
Constant Summary collapse
- MSG =
'Feature spec file has %<count>d examples, which exceeds the maximum of %<max>d. ' \ 'Consider splitting into smaller, focused files grouped by user flow or feature area.'
Instance Method Summary collapse
- #on_block(node) ⇒ Object (also: #on_numblock)
- #on_investigation_end ⇒ Object
- #on_new_investigation ⇒ Object
Instance Method Details
#on_block(node) ⇒ Object Also known as: on_numblock
34 35 36 |
# File 'lib/rubocop/cop/rspec/feature_spec_max_examples.rb', line 34 def on_block(node) @example_count += 1 if example?(node) end |
#on_investigation_end ⇒ Object
39 40 41 |
# File 'lib/rubocop/cop/rspec/feature_spec_max_examples.rb', line 39 def on_investigation_end add_global_offense(format(MSG, count: @example_count, max: @max)) if @example_count > @max end |
#on_new_investigation ⇒ Object
28 29 30 31 32 |
# File 'lib/rubocop/cop/rspec/feature_spec_max_examples.rb', line 28 def on_new_investigation super @example_count = 0 @max = cop_config['Max'] || 25 end |