Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix match_array to truly accept non-array #213

Merged
merged 1 commit into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/super_diff/rspec/monkey_patches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,14 @@ def self.prepended(base)
end

def match_array(items)
BuiltIn::MatchArray.new(items.is_a?(String) ? [items] : items)
# This is a bit strange, but this is fundamentally different from
# splatting `items` in the argument list. It's functionally equivalent
# to, though not quite the same as:
#
# items.is_a?(Array) ? items : [items]
#
items = *items
BuiltIn::MatchArray.new(items)
end
end
end
Expand Down
22 changes: 11 additions & 11 deletions spec/integration/rspec/match_array_matcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,12 @@
end
end

context "when the input value is a string" do
it "produces the correct failure message when used in the positive" do
context "when the input value is not an array, and especially not a value that could be turned into one" do
fit "produces the correct failure message, as though an array had been given" do
as_both_colored_and_uncolored do |color_enabled|
snippet = <<~TEST.strip
actual = ["Marty", "Jennifer", "Doc"]
expected = "Einie"
actual = [:marty, :jennifer, :doc]
expected = :einie
expect(actual).to match_array(expected)
TEST
program = make_plain_test_program(snippet, color_enabled: color_enabled)
Expand All @@ -397,20 +397,20 @@
proc do
line do
plain "Expected "
actual %|["Marty", "Jennifer", "Doc"]|
actual "[:marty, :jennifer, :doc]"
plain " to match array with "
expected %|"Einie"|
expected ":einie"
plain "."
end
end,
diff:
proc do
plain_line " ["
actual_line %|+ "Marty",|
actual_line %|+ "Jennifer",|
actual_line %|+ "Doc",|
# expected_line %|- "Einie"| # TODO
expected_line %|- "Einie",|
actual_line "+ :marty,"
actual_line "+ :jennifer,"
actual_line "+ :doc,"
# expected_line %|- :einie| # TODO
expected_line "- :einie,"
plain_line " ]"
end
)
Expand Down
Loading