Skip to content

Commit

Permalink
Improve error message for negative any_instance spy expectations
Browse files Browse the repository at this point in the history
  • Loading branch information
Darhazer authored and JonRowe committed Jun 27, 2018
1 parent 7dc2a43 commit 51495b5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rspec/mocks/matchers/have_received.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ def setup_any_instance_expectation(_subject, &_block)
disallow("expect_any_instance_of")
end

def setup_any_instance_negative_expectation(_subject, &_block)
disallow("expect_any_instance_of")
end

private

def disallow(type, reason="")
Expand Down
8 changes: 8 additions & 0 deletions spec/rspec/mocks/matchers/have_received_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,14 @@ module Mocks
end
end

describe "expect_any_instance_of(...).not_to have_received" do
it "fails because we dont want to support it" do
_expect {
expect_any_instance_of(double).to have_received(:some_method)
}.to fail_with("Using expect_any_instance_of(...) with the `have_received` matcher is not supported.")
end
end

def double_with_met_expectation(method_name, *args)
double = double_with_unmet_expectation(method_name)
meet_expectation(double, method_name, *args)
Expand Down

0 comments on commit 51495b5

Please sign in to comment.