Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
guiferrpereira authored and mcmire committed Dec 18, 2020
1 parent 3463ac9 commit 034c902
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/super_diff/rspec/monkey_patches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ def expected_for_failure_message
end

def match_array(items)
BuiltIn::MatchArray.new(items)
BuiltIn::MatchArray.new(items.is_a?(String) ? [items] : items)
end
alias_matcher :an_array_matching, :match_array
end
Expand Down
42 changes: 42 additions & 0 deletions spec/integration/rspec/match_array_matcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -369,4 +369,46 @@
end
end
end

context "when the input value is a string" do
it "produces the correct failure message when used in the positive" do
as_both_colored_and_uncolored do |color_enabled|
snippet = <<~TEST.strip
expected = "Einie"
actual = ["Marty", "Jennifer", "Doc"]
expect(actual).to match_array(expected)
TEST
program = make_plain_test_program(
snippet,
color_enabled: color_enabled,
)

expected_output = build_expected_output(
color_enabled: color_enabled,
snippet: %|expect(actual).to match_array(expected)|,
expectation: proc {
line do
plain "Expected "
beta %|["Marty", "Jennifer", "Doc"]|
plain " to match array with "
alpha %|"Einie"|
plain "."
end
},
diff: proc {
plain_line %| [|
plain_line %| "Marty",|
plain_line %| "Jennifer",|
plain_line %| "Doc",|
alpha_line %|- "Einie"|
plain_line %| ]|
},
)

expect(program).
to produce_output_when_run(expected_output).
in_color(color_enabled)
end
end
end
end

0 comments on commit 034c902

Please sign in to comment.