Skip to content

Commit

Permalink
Merge pull request #1212 from SergiyYarinovskiy/issue-1210
Browse files Browse the repository at this point in the history
Fixes Issue #1210: Wrong negative expectation with once
  • Loading branch information
JonRowe authored Mar 26, 2018
2 parents 5cbe463 + b5bdc56 commit ff87136
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Metrics/BlockLength:
Max: 45

Metrics/ModuleLength:
Max: 209
Max: 210

Metrics/PerceivedComplexity:
Max: 19
1 change: 1 addition & 0 deletions lib/rspec/mocks/message_expectation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ def raise_already_invoked_error_if_necessary(calling_customization)
end

def set_expected_received_count(relativity, n)
raise "`count` is not supported with negative message expectations" if negative?
@at_least = (relativity == :at_least)
@at_most = (relativity == :at_most)
@exactly = (relativity == :exactly)
Expand Down
8 changes: 8 additions & 0 deletions spec/rspec/mocks/at_least_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ module Mocks
expect(@double.do_something).to eq 'bar'
expect(@double.do_something).to eq 'bar'
end

context "when called with negative expectation" do
it "raises an error" do
expect {
expect(@double).not_to receive(:do_something).at_least(:thrice)
}.to raise_error(/`count` is not supported with negative message expectations/)
end
end
end
end
end
8 changes: 8 additions & 0 deletions spec/rspec/mocks/at_most_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ module Mocks
@double.do_something
end
end

context "when called with negative expectation" do
it "raises an error" do
expect {
expect(@double).not_to receive(:do_something).at_most(:thrice)
}.to raise_error(/`count` is not supported with negative message expectations/)
end
end
end
end
end
8 changes: 8 additions & 0 deletions spec/rspec/mocks/once_counts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ module Mocks
}.to fail_with(a_string_including("expected: 1 time", "received: 2 times"))
end
end

context "when called with negative expectation" do
it "raises an error" do
expect {
expect(@double).not_to receive(:do_something).once
}.to raise_error(/`count` is not supported with negative message expectations/)
end
end
end
end
end
8 changes: 8 additions & 0 deletions spec/rspec/mocks/thrice_counts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ module Mocks
}.to fail
reset @double
end

context "when called with negative expectation" do
it "raises an error" do
expect {
expect(@double).not_to receive(:do_something).thrice
}.to raise_error(/`count` is not supported with negative message expectations/)
end
end
end
end
end
8 changes: 8 additions & 0 deletions spec/rspec/mocks/twice_counts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ module Mocks
}.to fail_with(a_string_including("expected: 2 times", "received: 3 times"))
end
end

context "when called with negative expectation" do
it "raises an error" do
expect {
expect(@double).not_to receive(:do_something).twice
}.to raise_error(/`count` is not supported with negative message expectations/)
end
end
end
end
end

0 comments on commit ff87136

Please sign in to comment.