Consistent location fields

This commit is contained in:
Michael Miller 2021-06-02 23:09:30 -06:00
parent 8f3a7c0a5a
commit 39e917ce57
No known key found for this signature in database
GPG key ID: F9A0C5C65B162436
2 changed files with 2 additions and 8 deletions

View file

@ -56,7 +56,8 @@ module Spectator
# Creates the JSON representation of the expectation.
def to_json(json : JSON::Builder)
json.object do
json.field("location") { @location.to_json(json) }
json.field("file_path", @location.path)
json.field("line_number", @location.line)
json.field("satisfied", satisfied?)
if (failed = @match_data.as?(Matchers::FailedMatchData))
failed_to_json(failed, json)

View file

@ -1,5 +1,3 @@
require "json"
module Spectator
# Defines the file and line number a piece of code originated from.
struct Location
@ -64,10 +62,5 @@ module Spectator
def to_s(io)
io << path << ':' << line
end
# Creates the JSON representation of the location.
def to_json(json : ::JSON::Builder)
json.string(to_s)
end
end
end