Skip to content

Commit c685536

Browse files
mcmirejas14
andauthored
Fix raise_error messages when expected error is a matcher (#214)
Co-authored-by: Joe Stein <[email protected]>
1 parent 4cdb495 commit c685536

File tree

3 files changed

+450
-4
lines changed

3 files changed

+450
-4
lines changed

lib/super_diff/rspec/monkey_patches.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -734,11 +734,9 @@ def actual_for_diff
734734

735735
def expected_for_matcher_text
736736
if @expected_message
737-
"#<#{@expected_error.name} #{description_of(@expected_message)}>"
738-
elsif @expected_error.is_a? Regexp
739-
"#<Exception #{description_of(@expected_error)}>"
737+
"#<#{describe_expected_error} #{description_of(@expected_message)}>"
740738
else
741-
"#<#{@expected_error.name}>"
739+
"#<#{describe_expected_error}>"
742740
end
743741
end
744742

@@ -757,6 +755,20 @@ def expected_action_for_failure_message
757755
def matcher_text_builder_class
758756
SuperDiff::RSpec::MatcherTextBuilders::RaiseError
759757
end
758+
759+
private
760+
761+
def describe_expected_error
762+
if @expected_error.is_a? Class
763+
@expected_error.name
764+
elsif @expected_error.is_a? Regexp
765+
"Exception #{description_of(@expected_error)}"
766+
elsif @expected_error.respond_to? :description
767+
@expected_error.description
768+
else
769+
SuperDiff.inspect_object(@expected_error, as_lines: false)
770+
end
771+
end
760772
end
761773

762774
def self.matcher_name

0 commit comments

Comments
 (0)