Skip to content

Commit 034c902

Browse files
guiferrpereiramcmire
authored andcommitted
1 parent 3463ac9 commit 034c902

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

lib/super_diff/rspec/monkey_patches.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ def expected_for_failure_message
729729
end
730730

731731
def match_array(items)
732-
BuiltIn::MatchArray.new(items)
732+
BuiltIn::MatchArray.new(items.is_a?(String) ? [items] : items)
733733
end
734734
alias_matcher :an_array_matching, :match_array
735735
end

spec/integration/rspec/match_array_matcher_spec.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,4 +369,46 @@
369369
end
370370
end
371371
end
372+
373+
context "when the input value is a string" do
374+
it "produces the correct failure message when used in the positive" do
375+
as_both_colored_and_uncolored do |color_enabled|
376+
snippet = <<~TEST.strip
377+
expected = "Einie"
378+
actual = ["Marty", "Jennifer", "Doc"]
379+
expect(actual).to match_array(expected)
380+
TEST
381+
program = make_plain_test_program(
382+
snippet,
383+
color_enabled: color_enabled,
384+
)
385+
386+
expected_output = build_expected_output(
387+
color_enabled: color_enabled,
388+
snippet: %|expect(actual).to match_array(expected)|,
389+
expectation: proc {
390+
line do
391+
plain "Expected "
392+
beta %|["Marty", "Jennifer", "Doc"]|
393+
plain " to match array with "
394+
alpha %|"Einie"|
395+
plain "."
396+
end
397+
},
398+
diff: proc {
399+
plain_line %| [|
400+
plain_line %| "Marty",|
401+
plain_line %| "Jennifer",|
402+
plain_line %| "Doc",|
403+
alpha_line %|- "Einie"|
404+
plain_line %| ]|
405+
},
406+
)
407+
408+
expect(program).
409+
to produce_output_when_run(expected_output).
410+
in_color(color_enabled)
411+
end
412+
end
413+
end
372414
end

0 commit comments

Comments
 (0)