From d6ed640f4f8be1044c945f57f5015ad2c1cd9be0 Mon Sep 17 00:00:00 2001 From: Tim Cowlishaw Date: Sun, 14 Jul 2013 11:10:45 +0100 Subject: [PATCH] warn rather than raise when block passed to have_received. Add spec for file / line number --- lib/rspec/mocks/example_methods.rb | 2 +- spec/rspec/mocks/matchers/have_received_spec.rb | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/rspec/mocks/example_methods.rb b/lib/rspec/mocks/example_methods.rb index 199576be4..27d5ae944 100644 --- a/lib/rspec/mocks/example_methods.rb +++ b/lib/rspec/mocks/example_methods.rb @@ -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 diff --git a/spec/rspec/mocks/matchers/have_received_spec.rb b/spec/rspec/mocks/matchers/have_received_spec.rb index a270d37de..4360fc770 100644 --- a/spec/rspec/mocks/matchers/have_received_spec.rb +++ b/spec/rspec/mocks/matchers/have_received_spec.rb @@ -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