Use location instead of source

This commit is contained in:
Michael Miller 2021-07-17 16:12:10 -06:00
parent 7e2b267e93
commit 81f1966417
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
3 changed files with 13 additions and 13 deletions

View file

@ -41,7 +41,7 @@ module Spectator
# Attempts to retrieve the location where the example failed.
# This only works if the location of the failed expectation was reported.
# If available, returns a `Location`, otherwise `nil`.
def source : Location?
def location : Location?
return unless error = @error.as?(ExampleFailed)
error.location?

View file

@ -15,8 +15,8 @@ module Spectator::Formatting::Components
io.puts
@failures.each do |failure|
# Use failed location if it's available.
if (result = failure.result).responds_to?(:source)
location = result.source
if (result = failure.result).responds_to?(:location)
location = result.location
end
io.puts ExampleCommand.new(failure, location).colorize(:red)

View file

@ -48,7 +48,7 @@ module Spectator::Formatting::Components
subtitle_line(io)
io.puts
content(io)
source_line(io)
location_line(io)
end
end
@ -68,16 +68,16 @@ module Spectator::Formatting::Components
end
end
# Produces the (example) source line.
private def source_line(io)
source = if (result = @example.result).responds_to?(:source)
result.source
else
@example.location?
end
return unless source
# Produces the (example) location line.
private def location_line(io)
location = if (result = @example.result).responds_to?(:location)
result.location
else
@example.location?
end
return unless location
line(io) { io << Comment.colorize(source) }
line(io) { io << Comment.colorize(location) }
end
# Computes the number of spaces the index takes