From 63f2e2c37783a0ddb41d96f984c65f4b1a6acf73 Mon Sep 17 00:00:00 2001 From: Eric Mueller Date: Thu, 9 May 2024 14:03:15 -0400 Subject: [PATCH] Add tests checking handling of single-line string arrays (as described in rspec-expectations/#415) --- spec/rspec/support/differ_spec.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/spec/rspec/support/differ_spec.rb b/spec/rspec/support/differ_spec.rb index cbd1ed28f..3d84b3c09 100644 --- a/spec/rspec/support/differ_spec.rb +++ b/spec/rspec/support/differ_spec.rb @@ -116,6 +116,36 @@ module Support expect { differ.diff(actual, expected) }.not_to change { differ_ivars } end + it 'returns the expected diff for arrays of single-line strings' do + expected = ["foo"] + actual = ["foo", "bar"] + + expected_diff = dedent(<<-'EOS') + | + |@@ -1,2 +1,3 @@ + | foo + |+bar + | + EOS + diff = differ.diff(actual, expected) + expect(diff).to eq(expected_diff) + end + + it 'does not give an empty string for single-element arrays of single-line strings' do + expected = ["foo"] + actual = ["bar"] + + expected_diff = dedent(<<-'EOS') + | + |@@ -1 +1 @@ + |-foo + |+bar + | + EOS + diff = differ.diff(actual, expected) + expect(diff).to eq(expected_diff) + end + def differ_ivars Hash[ differ.instance_variables.map do |ivar| [ivar, differ.instance_variable_get(ivar)]