Don't use failure location in failed example block output

This is problematic, since the failure could have ocurred outside the 
example block (in a method call).
The comment line under the failure details will still point to the 
result location, if it's available.
This commit is contained in:
Michael Miller 2021-07-17 16:15:11 -06:00
parent 81f1966417
commit 7cb1545e83
No known key found for this signature in database
GPG Key ID: FB9F12F7C646A4AD
3 changed files with 5 additions and 12 deletions

View File

@ -1,14 +1,11 @@
require "../../example"
require "../../location"
require "./comment"
module Spectator::Formatting::Components
# Provides syntax for running a specific example from the command-line.
struct ExampleCommand
# Creates the component with the specified example.
# The location can be overridden, for instance, pointing to a problematic line in the example.
# Otherwise the example's location is used.
def initialize(@example : Example, @location : Location? = nil)
def initialize(@example : Example)
end
# Produces output for running the previously specified example.
@ -17,7 +14,7 @@ module Spectator::Formatting::Components
# Use location for argument if it's available, since it's simpler.
# Otherwise, use the example name filter argument.
if location = (@location || @example.location?)
if location = @example.location?
io << location
else
io << "-e " << @example

View File

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

View File

@ -68,7 +68,8 @@ module Spectator::Formatting::Components
end
end
# Produces the (example) location line.
# Produces the location line.
# This is where the result was determined.
private def location_line(io)
location = if (result = @example.result).responds_to?(:location)
result.location