From be0b14225ac5b896b8a88edc994fb74f913abbbc Mon Sep 17 00:00:00 2001 From: ronen barzel Date: Fri, 6 Jun 2014 00:36:23 +0100 Subject: [PATCH 1/3] Pass super() a Proc instead of Failure object As of a recent [commit](https://github.com/rspec/rspec-expectations/blame/79582c2c160ac7b3a58d3d128012b022c63d6174/lib/rspec/matchers/built_in/raise_error.rb#L38) to rspec-expectations, Rspec::Matchers::BuiltIn::RaiseError strictly requires a Proc rather than something that quacks like one. --- lib/given/rspec/have_failed_212.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/given/rspec/have_failed_212.rb b/lib/given/rspec/have_failed_212.rb index 78c85e3..7241563 100644 --- a/lib/given/rspec/have_failed_212.rb +++ b/lib/given/rspec/have_failed_212.rb @@ -7,7 +7,7 @@ module HaveFailed class HaveFailedMatcher < RSpec::Matchers::BuiltIn::RaiseError def matches?(given_proc, negative_expectation = false) if given_proc.is_a?(::Given::Failure) - super + super(lambda { given_proc.call }, negative_expectation) else super(lambda { }, negative_expectation) end @@ -15,7 +15,7 @@ def matches?(given_proc, negative_expectation = false) def does_not_match?(given_proc) if given_proc.is_a?(::Given::Failure) - super(given_proc) + super(lambda { given_proc.call }) else super(lambda { }) end From 545c797c39b197062777eecb492dbfe36e7ab1fe Mon Sep 17 00:00:00 2001 From: Justin Searls Date: Fri, 9 Jan 2015 10:52:38 -0500 Subject: [PATCH 2/3] Fixes a slight problem in @ronen's patch Reverts half of be0b14225ac5b896b8a88edc994fb74f913abbbc @ronen: it looks like what happened here is that does_not_match#super will pass whatever it is given into `matches?` and as a result, the matcher was never ever being passed an actual ::Given::Failure. This caused all of the (already red) negative cases to remain red even after the patch. --- lib/given/rspec/have_failed_212.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/given/rspec/have_failed_212.rb b/lib/given/rspec/have_failed_212.rb index 7241563..822bb10 100644 --- a/lib/given/rspec/have_failed_212.rb +++ b/lib/given/rspec/have_failed_212.rb @@ -15,7 +15,7 @@ def matches?(given_proc, negative_expectation = false) def does_not_match?(given_proc) if given_proc.is_a?(::Given::Failure) - super(lambda { given_proc.call }) + super(given_proc) else super(lambda { }) end From cb54550f741f42511a32cd93e83cb583b4e0c3e4 Mon Sep 17 00:00:00 2001 From: Justin Searls Date: Fri, 9 Jan 2015 10:56:51 -0500 Subject: [PATCH 3/3] Pass `expect` a block when matching `raise_error` --- spec/lib/given/failure_spec.rb | 6 +++--- spec/lib/given/have_failed_spec.rb | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/lib/given/failure_spec.rb b/spec/lib/given/failure_spec.rb index 485897b..ad93094 100644 --- a/spec/lib/given/failure_spec.rb +++ b/spec/lib/given/failure_spec.rb @@ -21,9 +21,9 @@ end describe "raising error" do - Then { expect(failure).to raise_error(StandardError, "Oops") } - Then { expect(failure).to raise_error(StandardError) } - Then { expect(failure).to raise_error } + Then { expect { failure.call }.to raise_error(StandardError, "Oops") } + Then { expect { failure.call }.to raise_error(StandardError) } + Then { expect { failure.call }.to raise_error } end describe "== have_failed" do diff --git a/spec/lib/given/have_failed_spec.rb b/spec/lib/given/have_failed_spec.rb index b51b0cd..c3e7256 100644 --- a/spec/lib/given/have_failed_spec.rb +++ b/spec/lib/given/have_failed_spec.rb @@ -9,7 +9,7 @@ module HaveFailedSpec context "with a failure" do When(:result) { fail CustomError, "Ouch" } - Then { expect(result).to raise_error(CustomError, "Ouch") } + Then { expect { result.call }.to raise_error(CustomError, "Ouch") } Then { expect(result).to have_failed(CustomError, "Ouch") } Then { expect(result).to have_raised(CustomError, "Ouch") } @@ -23,10 +23,10 @@ module HaveFailedSpec context "with a standard failure" do When(:result) { fail "Ouch" } - Then { expect(result).to raise_error(StandardError, "Ouch") } - Then { expect(result).to raise_error(StandardError, /^O/) } - Then { expect(result).to raise_error(StandardError) } - Then { expect(result).to raise_error } + Then { expect { result.call }.to raise_error(StandardError, "Ouch") } + Then { expect { result.call }.to raise_error(StandardError, /^O/) } + Then { expect { result.call }.to raise_error(StandardError) } + Then { expect { result.call }.to raise_error } Then { expect(result).to have_failed(StandardError, "Ouch") } Then { expect(result).to have_failed(StandardError, /^O/) }