Skip to content

Suggestion: ExpectChange cop applied on negated matcher #813

@Drowze

Description

@Drowze

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?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions