rubocop-rspec icon indicating copy to clipboard operation
rubocop-rspec copied to clipboard

Suggestion: ExpectChange cop applied on negated matcher

Open Drowze opened this issue 6 years ago • 1 comments

On RSpec one can do:

expect { ... }.to change { ... }
              .and change { ... }

But it is not possible to do

expect { ... }.not_to change { ... }
              .and_not change { ... }

A common solution for this is defining a negated matcher for change:

RSpec::Matchers.define_negated_matcher :not_change, :change

...
expect { ... }.to not_change { ... }
              .and not_change { ... }

On doing this however, we lose the ExpectChange cop usefulness. I thought of creating a custom cop for it for my needs, as not_change is not standard. However, being it a common practice, I think that it would be nice for the ExpectChange cop to have an option where you'd explicit the negated matcher method.

e.g.:

RSpec/ExpectChange:
  NegatedMatcher: not_change

What do you think?

Drowze avatar Aug 21 '19 14:08 Drowze

Seems closely related to https://github.com/rubocop-hq/rubocop-rspec/issues/333

pirj avatar Aug 21 '19 14:08 pirj