Fix various expectation type code

This commit is contained in:
Michael Miller 2019-08-08 21:52:05 -06:00
parent 21e10c1ef2
commit 3b1a5a1121
2 changed files with 9 additions and 9 deletions

View file

@ -9,7 +9,7 @@ module Spectator
# Creates the exception.
# The exception string is generated from the expecation message.
def initialize(@expectation)
super(@expectation.actual_message)
super(@expectation.failure_message)
end
end
end

View file

@ -9,7 +9,7 @@ module Spectator::Expectations
getter source : Source
# Creates the expectation.
def initialize(@match_data : MatchData, @source : Source)
def initialize(@match_data : Matchers::MatchData, @source : Source)
end
def satisfied?
@ -21,19 +21,19 @@ module Spectator::Expectations
end
def failure_message?
@match_data.as?(FailedMatchData).try(&.failure_message)
@match_data.as?(Matchers::FailedMatchData).try(&.failure_message)
end
def failure_message
@match_data.as(FailedMatchData).failure_message
@match_data.as(Matchers::FailedMatchData).failure_message
end
def values?
@match_data.as?(FailedMatchData).try(&.values)
@match_data.as?(Matchers::FailedMatchData).try(&.values)
end
def values
@match_data.as(FailedMatchData).values
@match_data.as(Matchers::FailedMatchData).values
end
# Creates the JSON representation of the expectation.
@ -41,18 +41,18 @@ module Spectator::Expectations
json.object do
json.field("source") { @source.to_json(json) }
json.field("satisfied", satisfied?)
if (failed = @match_data.as?(FailedMatchData))
if (failed = @match_data.as?(Matchers::FailedMatchData))
failed_to_json(failed, json)
end
end
end
private def failed_to_json(failed : FailedMatchData, json : ::JSON::Builder)
private def failed_to_json(failed : Matchers::FailedMatchData, json : ::JSON::Builder)
json.field("failure", failed.failure_message)
json.field("values") do
json.object do
failed.values.each do |pair|
json.field(pair.label, pair.value)
json.field(pair.first, pair.last)
end
end
end