From ae29d9f7079bead71739a77db463acef8c585a8d Mon Sep 17 00:00:00 2001 From: Joe Stein Date: Mon, 1 Jan 2024 13:26:58 -0800 Subject: [PATCH] Accept lazy `actual` descriptions --- lib/super_diff/rspec/augmented_matcher.rb | 2 +- lib/super_diff/rspec/matcher_text_builders/base.rb | 4 +++- lib/super_diff/rspec/monkey_patches.rb | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/super_diff/rspec/augmented_matcher.rb b/lib/super_diff/rspec/augmented_matcher.rb index 54dd8521..3a860aef 100644 --- a/lib/super_diff/rspec/augmented_matcher.rb +++ b/lib/super_diff/rspec/augmented_matcher.rb @@ -50,7 +50,7 @@ def matcher_text_builder_args end def actual_for_matcher_text - description_of(actual) + -> { description_of(actual) } end def expected_for_matcher_text diff --git a/lib/super_diff/rspec/matcher_text_builders/base.rb b/lib/super_diff/rspec/matcher_text_builders/base.rb index 5566fff5..42586354 100644 --- a/lib/super_diff/rspec/matcher_text_builders/base.rb +++ b/lib/super_diff/rspec/matcher_text_builders/base.rb @@ -92,7 +92,9 @@ def actual_phrase end def add_actual_value - template.add_text_in_color(actual_color) { actual } + template.add_text_in_color(actual_color) do + actual.respond_to?(:call) ? actual.call : actual + end end def expected_section diff --git a/lib/super_diff/rspec/monkey_patches.rb b/lib/super_diff/rspec/monkey_patches.rb index b4bd6cfe..02707c0b 100644 --- a/lib/super_diff/rspec/monkey_patches.rb +++ b/lib/super_diff/rspec/monkey_patches.rb @@ -532,7 +532,7 @@ def failure_message_when_negated # Override to use the whole object, not just part of it def actual_for_matcher_text - description_of(@actual) + -> { description_of(@actual) } end # Override to use (...) as delimiters rather than {...}