Skip to content

Commit

Permalink
warn rather than raise when block passed to have_received. Add spec f…
Browse files Browse the repository at this point in the history
…or file / line number
  • Loading branch information
timcowlishaw committed Jul 14, 2013
1 parent 49c9f09 commit d6ed640
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/rspec/mocks/example_methods.rb
Expand Up @@ -114,7 +114,7 @@ def hide_const(constant_name)
# # You can also use most message expectations:
# expect(invitation).to have_received(:accept).with(mailer).once
def have_received(method_name)
raise "have_received matcher does not take a block argument. Called from #{caller[0]}" if block_given?
warn "have_received ignores its block argument. Called from #{caller[0]}" if block_given?
Matchers::HaveReceived.new(method_name)
end

Expand Down
10 changes: 6 additions & 4 deletions spec/rspec/mocks/matchers/have_received_spec.rb
Expand Up @@ -60,11 +60,13 @@ module Mocks
}.to raise_error(/0 times/)
end

it "raises an exception when a block is used to match the arguments" do
it "warns when a block is used to match the arguments" do
dbl = double_with_met_expectation(:expected_method)
expect {
expect(dbl).to have_received(:expected_method) { }
}.to raise_error(/have_received matcher does not take a block argument/)
self.stub(:warn => nil)
expect(dbl).to have_received(:expected_method) { }; line = __LINE__
file = __FILE__
message = /have_received ignores its block argument. Called from #{file}:#{line}/
expect(self).to have_received(:warn).with(message)
end

context "with" do
Expand Down

0 comments on commit d6ed640

Please sign in to comment.