lib/rubocop/cop/rspec/change_by_zero.rb in rubocop-rspec-2.11.1 vs lib/rubocop/cop/rspec/change_by_zero.rb in rubocop-rspec-2.12.0
- old
+ new
@@ -7,20 +7,25 @@
#
# @example
# # bad
# expect { run }.to change(Foo, :bar).by(0)
# expect { run }.to change { Foo.bar }.by(0)
+ #
+ # # bad - compound expectations
# expect { run }
# .to change(Foo, :bar).by(0)
# .and change(Foo, :baz).by(0)
# expect { run }
# .to change { Foo.bar }.by(0)
# .and change { Foo.baz }.by(0)
#
# # good
# expect { run }.not_to change(Foo, :bar)
# expect { run }.not_to change { Foo.bar }
+ #
+ # # good - compound expectations
+ # define_negated_matcher :not_change, :change
# expect { run }
# .to not_change(Foo, :bar)
# .and not_change(Foo, :baz)
# expect { run }
# .to not_change { Foo.bar }
@@ -50,20 +55,20 @@
(int 0))
PATTERN
def on_send(node)
expect_change_with_arguments(node.parent) do
- check_offence(node.parent)
+ check_offense(node.parent)
end
expect_change_with_block(node.parent.parent) do
- check_offence(node.parent.parent)
+ check_offense(node.parent.parent)
end
end
private
- def check_offence(node)
+ def check_offense(node)
expression = node.loc.expression
if compound_expectations?(node)
add_offense(expression, message: MSG_COMPOUND)
else
add_offense(expression) do |corrector|