Merge branch 'type-matcher-actual-fix' into 'release/0.8'

Fix the actual type reported by the type matcher

See merge request arctic-fox/spectator!5
This commit is contained in:
Mike Miller 2019-06-02 03:37:41 +00:00
commit 2eb6bc4ea2
2 changed files with 11 additions and 3 deletions

View file

@ -74,6 +74,14 @@ describe Spectator::Matchers::TypeMatcher do
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data.values, :actual)[:value].should eq(typeof(value))
end
it "is the runtime type name" do
value = 42.as(Int32?)
partial = new_partial(value)
matcher = Spectator::Matchers::TypeMatcher(String).new
match_data = matcher.match(partial)
match_data_value_sans_prefix(match_data.values, :actual)[:value].should eq(value.class)
end
end
end

View file

@ -19,13 +19,13 @@ module Spectator::Matchers
# `MatchData` is returned that contains information about the match.
def match(partial)
actual = partial.actual
MatchData(Expected, typeof(actual)).new(match?(actual), partial.label)
MatchData(Expected, typeof(actual)).new(match?(actual), actual, partial.label)
end
# Match data specific to this matcher.
private struct MatchData(ExpectedType, ActualType) < MatchData
# Creates the match data.
def initialize(matched, @actual_label : String)
def initialize(matched, @actual : ActualType, @actual_label : String)
super(matched)
end
@ -33,7 +33,7 @@ module Spectator::Matchers
def named_tuple
{
expected: NegatableMatchDataValue.new(ExpectedType),
actual: ActualType,
actual: @actual.class,
}
end