mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Move the remaining to_json methods to their own types
This commit is contained in:
parent
b12c1aba96
commit
09b6dee004
5 changed files with 34 additions and 41 deletions
|
@ -53,5 +53,11 @@ module Spectator
|
|||
io << ' ' unless symbolic? && @group.symbolic?
|
||||
io << what
|
||||
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
|
||||
|
|
|
@ -51,5 +51,12 @@ module Spectator::Expectations
|
|||
def failed?
|
||||
!successful?
|
||||
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
|
||||
|
|
|
@ -40,5 +40,21 @@ module Spectator::Expectations
|
|||
def actual_message
|
||||
@match_data.matched? ? @match_data.message : @match_data.negated_message
|
||||
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
|
||||
|
|
|
@ -36,44 +36,3 @@ module Spectator::Formatting
|
|||
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
|
||||
|
|
|
@ -41,5 +41,10 @@ module Spectator
|
|||
io << ':'
|
||||
io << line
|
||||
end
|
||||
|
||||
# Creates the JSON representation of the source.
|
||||
def to_json(json : ::JSON::Builder)
|
||||
json.string(to_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue