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].'
- ANYTHING =
->(_node) { true }
- TRUE =
->(node) { node.true_type? }
Instance Method Summary collapse
Methods inherited from Base
inherited, #on_new_investigation
Methods included from RSpec::Language::NodePattern
Instance Method Details
#on_block(node) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rubocop/cop/rspec/multiple_expectations.rb', line 68 def on_block(node) return unless example?(node) return if example_with_aggregate_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 |