Permalink
Browse files

fix for change by(0) bug

- Closes #17.
  • Loading branch information...
ignu authored and dchelimsky committed Sep 23, 2010
1 parent 311ba91 commit fa4446d3ef6b1edc85da7e706d6773eb918d124f
Showing with 7 additions and 2 deletions.
  1. +3 −2 lib/rspec/matchers/change.rb
  2. +4 −0 spec/rspec/matchers/change_spec.rb
@@ -16,8 +16,9 @@ def matches?(event_proc)
@before = evaluate_value_proc
event_proc.call
@after = evaluate_value_proc
-
- changed? && matches_before? && matches_after? && matches_amount? && matches_min? && matches_max?
+
+ changed_if_expected = @amount == 0 || changed?
+ changed_if_expected && matches_before? && matches_after? && matches_amount? && matches_min? && matches_max?
end
def raise_block_syntax_error
@@ -123,6 +123,10 @@ class SomethingExpected
expect { @instance.some_value += 1 }.to change(@instance, :some_value).by(1)
end
+ it "passes when attribute is not changed and expected amount is 0" do
+ expect { @instance.some_value += 0 }.to change(@instance, :some_value).by(0)
+ end
+
it "fails when the attribute is changed by unexpected amount" do
expect do
expect { @instance.some_value += 2 }.to change(@instance, :some_value).by(1)

0 comments on commit fa4446d

Please sign in to comment.