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

View file

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

View file

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