Skip to content

Commit

Permalink
Add tests checking handling of single-line string arrays
Browse files Browse the repository at this point in the history
(as described in rspec-expectations/rspec#415)
  • Loading branch information
nevinera committed May 9, 2024
1 parent 8cbf7f9 commit 63f2e2c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions spec/rspec/support/differ_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit 63f2e2c

Please sign in to comment.