module RuboCop::Cop::RSpec::AggregateExamples::MatchersWithSideEffects
When aggregated, the expectations will fail when not supposed to or have a risk of not failing when expected to. One example is `validate_presence_of :comment` as it leaves an empty comment after itself on the subject making it invalid and the subsequent expectation to fail. Examples with those matchers are not supposed to be aggregated.
@example MatchersWithSideEffects
# .rubocop.yml # RSpec/AggregateExamples: # MatchersWithSideEffects: # - allow_value # - allow_values # - validate_presence_of # bad, but isn't automatically correctable describe do it { is_expected.to validate_presence_of(:comment) } it { is_expected.to be_valid } end
@internal
Support for taking special care of the matchers that have side effects, i.e. leave the subject in a modified state.
Constants
- MSG_FOR_EXPECTATIONS_WITH_SIDE_EFFECTS
Private Instance Methods
matcher_with_side_effects_name?(matcher_name)
click to toggle source
# File lib/test_prof/cops/rspec/aggregate_examples/matchers_with_side_effects.rb, line 55 def matcher_with_side_effects_name?(matcher_name) matcher_with_side_effects_names.include?(matcher_name) end
matcher_with_side_effects_names()
click to toggle source
# File lib/test_prof/cops/rspec/aggregate_examples/matchers_with_side_effects.rb, line 50 def matcher_with_side_effects_names cop_config.fetch("MatchersWithSideEffects", []) .map(&:to_sym) end
message_for(example, first_example)
click to toggle source
Calls superclass method
# File lib/test_prof/cops/rspec/aggregate_examples/matchers_with_side_effects.rb, line 44 def message_for(example, first_example) return super unless example_with_side_effects?(example) format(MSG_FOR_EXPECTATIONS_WITH_SIDE_EFFECTS, first_example.loc.line) end