Mimic RSpec behavior of match matcher

The code:
expect(/foo/).to match("food")
would normally evaluate:
"food" === /foo/
which is false.
However, in RSpec, this expectation is true.
This commit is contained in:
Michael Miller 2020-01-06 23:01:45 -07:00
parent b433511201
commit f11b548f4e

View file

@ -16,6 +16,12 @@ module Spectator::Matchers
expected.value === actual.value
end
# Overload that takes a regex so that the operands are flipped.
# This mimics RSpec's behavior.
private def match?(actual : TestExpression(Regex)) : Bool forall T
actual.value === expected.value
end
# Message displayed when the matcher isn't satisifed.
#
# This is only called when `#match?` returns false.