Skip to content

Commit d6c507b

Browse files
authored
Merge pull request #1295 from ydah/doc_improve_for_change_by_zero
Improved documentation for `RSpec/ChangeByZero`
2 parents bb046eb + 40b302b commit d6c507b

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

docs/modules/ROOT/pages/cops_rspec.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@ Prefer negated matchers over `to change.by(0)`.
404404
# bad
405405
expect { run }.to change(Foo, :bar).by(0)
406406
expect { run }.to change { Foo.bar }.by(0)
407+
408+
# bad - compound expectations
407409
expect { run }
408410
.to change(Foo, :bar).by(0)
409411
.and change(Foo, :baz).by(0)
@@ -414,6 +416,9 @@ expect { run }
414416
# good
415417
expect { run }.not_to change(Foo, :bar)
416418
expect { run }.not_to change { Foo.bar }
419+
420+
# good - compound expectations
421+
define_negated_matcher :not_change, :change
417422
expect { run }
418423
.to not_change(Foo, :bar)
419424
.and not_change(Foo, :baz)

lib/rubocop/cop/rspec/change_by_zero.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ module RSpec
99
# # bad
1010
# expect { run }.to change(Foo, :bar).by(0)
1111
# expect { run }.to change { Foo.bar }.by(0)
12+
#
13+
# # bad - compound expectations
1214
# expect { run }
1315
# .to change(Foo, :bar).by(0)
1416
# .and change(Foo, :baz).by(0)
@@ -19,6 +21,9 @@ module RSpec
1921
# # good
2022
# expect { run }.not_to change(Foo, :bar)
2123
# expect { run }.not_to change { Foo.bar }
24+
#
25+
# # good - compound expectations
26+
# define_negated_matcher :not_change, :change
2227
# expect { run }
2328
# .to not_change(Foo, :bar)
2429
# .and not_change(Foo, :baz)

0 commit comments

Comments
 (0)