From 0a48b5f4473c121e3513a87fa8503285e350ed56 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Thu, 28 Feb 2019 16:30:56 -0700 Subject: [PATCH] Use block with line method --- src/spectator/formatters/failure_block.cr | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/spectator/formatters/failure_block.cr b/src/spectator/formatters/failure_block.cr index 2e412a6..3575195 100644 --- a/src/spectator/formatters/failure_block.cr +++ b/src/spectator/formatters/failure_block.cr @@ -43,7 +43,7 @@ module Spectator::Formatters # 1) Example name # ``` private def title(io) - line(io, NumberedItem.new(@index, @result.example)) + line(io) { io << NumberedItem.new(@index, @result.example) } end # Produces the message line of the failure block. @@ -54,22 +54,22 @@ module Spectator::Formatters # The indentation of this line starts directly under # the example name from the title line. private def message(io) - line(io, FailureMessage.color(@result)) + line(io) { io << FailureMessage.color(@result) } end # Produces the values list of the failure block. private def values(io) io.puts indent do - line(io, "Expected: TODO") - line(io, " got: TODO") + line(io) { io << "Expected: TODO" } + line(io) { io << " got: TODO" } end io.puts end # Produces the source line of the failure block. private def source(io) - line(io, Comment.color(@result.example.source)) + line(io) { io << Comment.color(@result.example.source) } end # Increases the indentation for a block of text. @@ -81,9 +81,10 @@ module Spectator::Formatters end # Produces a line of text with a leading indent. - private def line(io, text) + private def line(io) @indent.times { io << ' ' } - io.puts text + yield + io.puts end # Gets the number of characters a positive integer spans in base 10.