|
25 | 25 | RUBY |
26 | 26 | end |
27 | 27 |
|
| 28 | + it 'registers an offense when the argument to `by` is zero, ' \ |
| 29 | + 'but does not correct if it is `not_to` `change` already' do |
| 30 | + expect_offense(<<-RUBY) |
| 31 | + it do |
| 32 | + expect { foo }.not_to change(Foo, :bar).by(0) |
| 33 | + ^^^^^^^^^^^^^^^^^^^^^^^ Prefer `not_to change` over `to change.by(0)`. |
| 34 | + expect { foo }.not_to change(::Foo, :bar).by(0) |
| 35 | + ^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `not_to change` over `to change.by(0)`. |
| 36 | + expect { foo }.not_to change { Foo.bar }.by(0) |
| 37 | + ^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `not_to change` over `to change.by(0)`. |
| 38 | + expect { foo }.not_to change(Foo, :bar).by 0 |
| 39 | + ^^^^^^^^^^^^^^^^^^^^^^ Prefer `not_to change` over `to change.by(0)`. |
| 40 | + end |
| 41 | + RUBY |
| 42 | + |
| 43 | + expect_no_corrections |
| 44 | + end |
| 45 | + |
28 | 46 | it 'registers an offense when the argument to `by` is zero ' \ |
29 | 47 | 'with compound expectations' do |
30 | 48 | expect_offense(<<-RUBY) |
|
39 | 57 | ^^^^^^^^^^^^^^^^^^^^^^^^ Prefer negated matchers with compound expectations over `change.by(0)`. |
40 | 58 | .and change { Foo.baz }.by(0) |
41 | 59 | ^^^^^^^^^^^^^^^^^^^^^^^^ Prefer negated matchers with compound expectations over `change.by(0)`. |
| 60 | + expect { foo } |
| 61 | + .to change(Foo, :bar).by(0) & |
| 62 | + ^^^^^^^^^^^^^^^^^^^^^^^ Prefer negated matchers with compound expectations over `change.by(0)`. |
| 63 | + change(Foo, :baz).by(0) |
| 64 | + ^^^^^^^^^^^^^^^^^^^^^^^ Prefer negated matchers with compound expectations over `change.by(0)`. |
| 65 | + expect { foo } |
| 66 | + .to change { Foo.bar }.by(0) & |
| 67 | + ^^^^^^^^^^^^^^^^^^^^^^^^ Prefer negated matchers with compound expectations over `change.by(0)`. |
| 68 | + change { Foo.baz }.by(0) |
| 69 | + ^^^^^^^^^^^^^^^^^^^^^^^^ Prefer negated matchers with compound expectations over `change.by(0)`. |
42 | 70 | expect { foo } |
43 | 71 | .to change(Foo, :bar).by(0) |
44 | 72 | ^^^^^^^^^^^^^^^^^^^^^^^ Prefer negated matchers with compound expectations over `change.by(0)`. |
|
49 | 77 | ^^^^^^^^^^^^^^^^^^^^^^^^ Prefer negated matchers with compound expectations over `change.by(0)`. |
50 | 78 | .or change { Foo.baz }.by(0) |
51 | 79 | ^^^^^^^^^^^^^^^^^^^^^^^^ Prefer negated matchers with compound expectations over `change.by(0)`. |
| 80 | + expect { foo } |
| 81 | + .to change(Foo, :bar).by(0) | |
| 82 | + ^^^^^^^^^^^^^^^^^^^^^^^ Prefer negated matchers with compound expectations over `change.by(0)`. |
| 83 | + change(Foo, :baz).by(0) |
| 84 | + ^^^^^^^^^^^^^^^^^^^^^^^ Prefer negated matchers with compound expectations over `change.by(0)`. |
| 85 | + expect { foo } |
| 86 | + .to change { Foo.bar }.by(0) | |
| 87 | + ^^^^^^^^^^^^^^^^^^^^^^^^ Prefer negated matchers with compound expectations over `change.by(0)`. |
| 88 | + change { Foo.baz }.by(0) |
| 89 | + ^^^^^^^^^^^^^^^^^^^^^^^^ Prefer negated matchers with compound expectations over `change.by(0)`. |
52 | 90 | end |
53 | 91 | RUBY |
| 92 | + |
| 93 | + expect_no_corrections |
54 | 94 | end |
55 | 95 |
|
56 | 96 | it 'does not register an offense when the argument to `by` is not zero' do |
|
0 commit comments