Skip to content

Instantly share code, notes, and snippets.

@adam12
Created July 25, 2022 20:21
Show Gist options
  • Save adam12/677199202cb76791b6e767563b93e908 to your computer and use it in GitHub Desktop.
Save adam12/677199202cb76791b6e767563b93e908 to your computer and use it in GitHub Desktop.
require "minitest/autorun"
class TestFoo < Minitest::Test
ArrayPattern = Struct.new(:pattern) do
def ===(other)
pattern.zip(other).all? { |(left, right)| left === right }
end
end
def assert_includes_pattern(collection, pattern)
array_pattern = ArrayPattern.new(pattern)
assert(collection.any? { _1 in ^array_pattern }, <<~EOM)
Expected #{collection.inspect} to contain #{pattern.inspect}
EOM
end
def test_assertion
users = [
["adam12", "#ruby"],
["ruby-bot", "#ruby"]
]
assert_includes_pattern users, ["adam12", String]
assert_includes_pattern users, ["adam12", "#libera"]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment