Allow contain matcher to take multiple values

This commit is contained in:
Michael Miller 2019-02-01 19:43:42 -07:00
parent 7c8239e55b
commit 85b4e6894b
2 changed files with 11 additions and 3 deletions

View file

@ -356,8 +356,14 @@ module Spectator::DSL
# expect("foobar").to contain('o')
# expect(%i[a b c]).to contain(:b)
# ```
macro contain(expected)
::Spectator::Matchers::ContainMatcher.new({{expected.stringify}}, {{expected}})
#
# Additionally, multiple arguments can be specified.
# ```
# expect("foobarbaz").to contain("foo", "bar")
# expect(%i[a b c]).to contain(:a, :b)
# ```
macro contain(*expected)
::Spectator::Matchers::ContainMatcher.new({{expected.splat.stringify}}, {{expected}})
end
# Indicates that some value or set should contain another value.

View file

@ -7,7 +7,9 @@ module Spectator::Matchers
# Determines whether the matcher is satisfied with the value given to it.
# True is returned if the match was successful, false otherwise.
def match?(partial)
partial.actual.includes?(expected)
expected.all? do |item|
partial.actual.includes?(item)
end
end
# Describes the condition that satisfies the matcher.