Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix raise_error messages when expected error is a matcher #214

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions lib/super_diff/rspec/monkey_patches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -734,11 +734,9 @@ def actual_for_diff

def expected_for_matcher_text
if @expected_message
"#<#{@expected_error.name} #{description_of(@expected_message)}>"
elsif @expected_error.is_a? Regexp
"#<Exception #{description_of(@expected_error)}>"
"#<#{describe_expected_error} #{description_of(@expected_message)}>"
else
"#<#{@expected_error.name}>"
"#<#{describe_expected_error}>"
end
end

Expand All @@ -757,6 +755,20 @@ def expected_action_for_failure_message
def matcher_text_builder_class
SuperDiff::RSpec::MatcherTextBuilders::RaiseError
end

private

def describe_expected_error
if @expected_error.is_a? Class
@expected_error.name
elsif @expected_error.is_a? Regexp
"Exception #{description_of(@expected_error)}"
elsif @expected_error.respond_to? :description
@expected_error.description
else
SuperDiff.inspect_object(@expected_error, as_lines: false)
end
end
end

def self.matcher_name
Expand Down
Loading
Loading