Create parameterless initializer for TypeMatcher

This commit is contained in:
Michael Miller 2019-01-19 14:28:52 -07:00
parent e66c0abcfb
commit 419b1322bf
2 changed files with 7 additions and 1 deletions

View file

@ -41,7 +41,7 @@ module Spectator::DSL
# expect(x).to be_a(Int32 | String)
# ```
macro be_a(expected)
::Spectator::Matchers::TypeMatcher({{expected}}).new({{expected.stringify}}, nil)
::Spectator::Matchers::TypeMatcher({{expected}}).new
end
end
end

View file

@ -4,6 +4,12 @@ module Spectator::Matchers
# Matcher that tests a value is of a specified type.
# The values are compared with the `#is_a?` method.
struct TypeMatcher(Expected) < ValueMatcher(Nil)
# Creates the type matcher.
# The `Expected` type param will be used to populate the underlying label.
def initialize
super(Expected.to_s, nil)
end
# 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 : Expectations::ValueExpectationPartial(ActualType)) : Bool forall ActualType