Module: RuboCop::Cop::RSpec::AggregateExamples::MatchersWithSideEffects

Extended by:
NodePattern::Macros
Includes:
Language
Included in:
RuboCop::Cop::RSpec::AggregateExamples
Defined in:
lib/rubocop/test_prof/cops/rspec/aggregate_examples/matchers_with_side_effects.rb

Overview

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.

Examples:

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

Constant Summary collapse

MSG_FOR_EXPECTATIONS_WITH_SIDE_EFFECTS =
"Aggregate with the example at line %d. IMPORTANT! Pay attention " \
"to the expectation order, some of the matchers have side effects."

Constants included from Language

Language::RSPEC