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

View file

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

View file

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