Skip to content

Commit

Permalink
fix for change by(0) bug
Browse files Browse the repository at this point in the history
- Closes #17.
  • Loading branch information
ignu authored and dchelimsky committed Sep 23, 2010
1 parent 311ba91 commit fa4446d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/rspec/matchers/change.rb
Expand Up @@ -16,8 +16,9 @@ def matches?(event_proc)
@before = evaluate_value_proc @before = evaluate_value_proc
event_proc.call event_proc.call
@after = evaluate_value_proc @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 end


def raise_block_syntax_error def raise_block_syntax_error
Expand Down
4 changes: 4 additions & 0 deletions spec/rspec/matchers/change_spec.rb
Expand Up @@ -123,6 +123,10 @@ class SomethingExpected
expect { @instance.some_value += 1 }.to change(@instance, :some_value).by(1) expect { @instance.some_value += 1 }.to change(@instance, :some_value).by(1)
end 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 it "fails when the attribute is changed by unexpected amount" do
expect do expect do
expect { @instance.some_value += 2 }.to change(@instance, :some_value).by(1) expect { @instance.some_value += 2 }.to change(@instance, :some_value).by(1)
Expand Down

0 comments on commit fa4446d

Please sign in to comment.