Skip to content

Commit 4b45669

Browse files
numbatamcmire
authored andcommitted
Fix error when regex used in raise_error expectation. Issue #72
1 parent 4d60164 commit 4b45669

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/super_diff/rspec/monkey_patches.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,9 @@ def actual_for_diff
661661

662662
def expected_for_matcher_text
663663
if @expected_message
664-
"#<#{@expected_error.name} #{@expected_message.inspect}>"
664+
"#<#{@expected_error.name} #{description_of(@expected_message)}>"
665+
elsif @expected_error.is_a? Regexp
666+
"#<Exception #{description_of(@expected_error)}>"
665667
else
666668
"#<#{@expected_error.name}>"
667669
end

spec/unit/rspec/matchers/raise_error_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,28 @@
1818
end
1919
end
2020

21+
context "with regular expression as message (and assuming a RuntimeError)" do
22+
it "returns the correct output" do
23+
expect(raise_error(/hell/).description).to eq(
24+
%|raise error #<Exception /hell/>|,
25+
)
26+
end
27+
end
28+
2129
context "with both an exception and a message" do
2230
it "returns the correct output" do
2331
expect(raise_error(RuntimeError, "hell").description).to eq(
2432
%|raise error #<RuntimeError "hell">|,
2533
)
2634
end
2735
end
36+
37+
context "with an exception and a regular expression as message" do
38+
it "returns the correct output" do
39+
expect(raise_error(RuntimeError, /hell/).description).to eq(
40+
%|raise error #<RuntimeError /hell/>|,
41+
)
42+
end
43+
end
2844
end
2945
end

0 commit comments

Comments
 (0)