Class: RuboCop::Cop::RSpec::MultipleExpectations
- Includes:
- ConfigurableMax
- Defined in:
- lib/rubocop/cop/rspec/multiple_expectations.rb
Overview
Checks if examples contain too many ‘expect` calls.
This cop is configurable using the ‘Max` option and works with `–auto-gen-config`.
Constant Summary collapse
- MSG =
'Example has too many expectations [%<total>d/%<max>d].'
Constants inherited from Cop
Cop::DEFAULT_CONFIGURATION, Cop::DEFAULT_PATTERN_RE
Constants included from RSpec::Language
RSpec::Language::ALL, RSpec::Language::RSPEC
Instance Method Summary collapse
Methods inherited from Cop
Instance Method Details
#on_block(node) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rubocop/cop/rspec/multiple_expectations.rb', line 63 def on_block(node) return unless example?(node) return if example_with_aggregated_failures?(node) expectations_count = to_enum(:find_expectation, node).count return if expectations_count <= max_expectations self.max = expectations_count flag_example(node, expectation_count: expectations_count) end |