Move the remaining to_json methods to their own types

This commit is contained in:
Michael Miller 2019-03-22 21:29:20 -06:00
parent b12c1aba96
commit 09b6dee004
5 changed files with 34 additions and 41 deletions

View file

@ -53,5 +53,11 @@ module Spectator
io << ' ' unless symbolic? && @group.symbolic? io << ' ' unless symbolic? && @group.symbolic?
io << what io << what
end end
# Creates the JSON representation of the example,
# which is just its name.
def to_json(json : ::JSON::Builder)
json.string(to_s)
end
end end
end end

View file

@ -51,5 +51,12 @@ module Spectator::Expectations
def failed? def failed?
!successful? !successful?
end end
# Creates the JSON representation of the expectations.
def to_json(json : ::JSON::Builder)
json.array do
each &.to_json(json)
end
end
end end
end end

View file

@ -40,5 +40,21 @@ module Spectator::Expectations
def actual_message def actual_message
@match_data.matched? ? @match_data.message : @match_data.negated_message @match_data.matched? ? @match_data.message : @match_data.negated_message
end end
# Creates the JSON representation of the expectation.
def to_json(json : ::JSON::Builder)
json.object do
json.field("satisfied") { satisfied?.to_json(json) }
json.field("expected") { expected_message.to_json(json) }
json.field("actual") { actual_message.to_json(json) }
json.field("values") do
json.object do
values.each do |labeled_value|
json.field(labeled_value.label, labeled_value.value.to_s)
end
end
end
end
end
end end
end end

View file

@ -36,44 +36,3 @@ module Spectator::Formatting
end end
end end
end end
module Spectator
abstract class Example < ExampleComponent
def to_json(json : ::JSON::Builder)
json.string(to_s)
end
end
struct Source
def to_json(json : ::JSON::Builder)
json.string(to_s)
end
end
module Expectations
class ExampleExpectations
def to_json(json : ::JSON::Builder)
json.array do
each &.to_json(json)
end
end
end
class Expectation
def to_json(json : ::JSON::Builder)
json.object do
json.field("satisfied") { satisfied?.to_json(json) }
json.field("expected") { expected_message.to_json(json) }
json.field("actual") { actual_message.to_json(json) }
json.field("values") do
json.object do
values.each do |labeled_value|
json.field(labeled_value.label, labeled_value.value.to_s)
end
end
end
end
end
end
end
end

View file

@ -41,5 +41,10 @@ module Spectator
io << ':' io << ':'
io << line io << line
end end
# Creates the JSON representation of the source.
def to_json(json : ::JSON::Builder)
json.string(to_s)
end
end end
end end