Use block with line method

This commit is contained in:
Michael Miller 2019-02-28 16:30:56 -07:00
parent d5bef6f1da
commit 0a48b5f447

View file

@ -43,7 +43,7 @@ module Spectator::Formatters
# 1) Example name # 1) Example name
# ``` # ```
private def title(io) private def title(io)
line(io, NumberedItem.new(@index, @result.example)) line(io) { io << NumberedItem.new(@index, @result.example) }
end end
# Produces the message line of the failure block. # Produces the message line of the failure block.
@ -54,22 +54,22 @@ module Spectator::Formatters
# The indentation of this line starts directly under # The indentation of this line starts directly under
# the example name from the title line. # the example name from the title line.
private def message(io) private def message(io)
line(io, FailureMessage.color(@result)) line(io) { io << FailureMessage.color(@result) }
end end
# Produces the values list of the failure block. # Produces the values list of the failure block.
private def values(io) private def values(io)
io.puts io.puts
indent do indent do
line(io, "Expected: TODO") line(io) { io << "Expected: TODO" }
line(io, " got: TODO") line(io) { io << " got: TODO" }
end end
io.puts io.puts
end end
# Produces the source line of the failure block. # Produces the source line of the failure block.
private def source(io) private def source(io)
line(io, Comment.color(@result.example.source)) line(io) { io << Comment.color(@result.example.source) }
end end
# Increases the indentation for a block of text. # Increases the indentation for a block of text.
@ -81,9 +81,10 @@ module Spectator::Formatters
end end
# Produces a line of text with a leading indent. # Produces a line of text with a leading indent.
private def line(io, text) private def line(io)
@indent.times { io << ' ' } @indent.times { io << ' ' }
io.puts text yield
io.puts
end end
# Gets the number of characters a positive integer spans in base 10. # Gets the number of characters a positive integer spans in base 10.