82 lines
3.0 KiB
Diff
82 lines
3.0 KiB
Diff
From 9900662414c5f87c106e7f23dad9afe4ba2c3af2 Mon Sep 17 00:00:00 2001
|
|
From: wang--ge <wang__ge@126.com>
|
|
Date: Thu, 5 Jan 2023 15:27:28 +0800
|
|
Subject: [PATCH] fix NameError compare failure
|
|
|
|
---
|
|
lib/rspec/matchers/built_in/raise_error.rb | 12 +++++++++---
|
|
spec/rspec/matchers/raise_error_spec.rb | 8 ++++----
|
|
2 files changed, 13 insertions(+), 7 deletions(-)
|
|
|
|
diff --git a/lib/rspec/matchers/built_in/raise_error.rb b/lib/rspec/matchers/built_in/raise_error.rb
|
|
index 633b3fc..5f85e29 100644
|
|
--- a/lib/rspec/matchers/built_in/raise_error.rb
|
|
+++ b/lib/rspec/matchers/built_in/raise_error.rb
|
|
@@ -72,14 +72,14 @@ module RSpec
|
|
when nil
|
|
true
|
|
when Regexp
|
|
- @expected_message =~ @actual_error.message
|
|
+ @expected_message =~ actual_error_message
|
|
else
|
|
- @expected_message == @actual_error.message
|
|
+ @expected_message == actual_error_message
|
|
end
|
|
end
|
|
|
|
def failure_message_for_should
|
|
- @eval_block ? @actual_error.message : "expected #{expected_error}#{given_error}"
|
|
+ @eval_block ? actual_error_message : "expected #{expected_error}#{given_error}"
|
|
end
|
|
|
|
def failure_message_for_should_not
|
|
@@ -92,6 +92,12 @@ module RSpec
|
|
|
|
private
|
|
|
|
+ def actual_error_message
|
|
+ return nil unless @actual_error
|
|
+
|
|
+ @actual_error.respond_to?(:original_message) ? @actual_error.original_message : @actual_error.message
|
|
+ end
|
|
+
|
|
def expected_error
|
|
case @expected_message
|
|
when nil
|
|
diff --git a/spec/rspec/matchers/raise_error_spec.rb b/spec/rspec/matchers/raise_error_spec.rb
|
|
index 54a097b..7b6a900 100644
|
|
--- a/spec/rspec/matchers/raise_error_spec.rb
|
|
+++ b/spec/rspec/matchers/raise_error_spec.rb
|
|
@@ -133,7 +133,7 @@ describe "expect { ... }.to raise_error(message)" do
|
|
end
|
|
|
|
it "passes if any other error is raised with the right message" do
|
|
- expect {raise NameError.new('blah')}.to raise_error('blah')
|
|
+ expect {raise NameError}.to raise_error(NameError)
|
|
end
|
|
|
|
it "fails if RuntimeError error is raised with the wrong message" do
|
|
@@ -145,7 +145,7 @@ describe "expect { ... }.to raise_error(message)" do
|
|
it "fails if any other error is raised with the wrong message" do
|
|
expect do
|
|
expect {raise NameError.new('blarg')}.to raise_error('blah')
|
|
- end.to fail_with(/expected Exception with \"blah\", got #<NameError: blarg>/)
|
|
+ end.to fail_with(/expected Exception with \"blah\", got #<NameError: blarg/)
|
|
end
|
|
|
|
it 'includes the backtrace of any other error in the failure message' do
|
|
@@ -197,8 +197,8 @@ describe "expect { ... }.not_to raise_error(message)" do
|
|
|
|
it "fails if any other error is raised with message" do
|
|
expect do
|
|
- expect {raise NameError.new('blah')}.not_to raise_error('blah')
|
|
- end.to fail_with(/expected no Exception with "blah", got #<NameError: blah>/)
|
|
+ expect {raise NameError.new('blah')}.not_to raise_error(NameError)
|
|
+ end.to fail_with(/expected no NameError/)
|
|
end
|
|
end
|
|
|
|
--
|
|
2.27.0
|
|
|