From 21da4b7c361d9ab96c585d1fc5f037db442b6619 Mon Sep 17 00:00:00 2001 From: Kazato Sugimoto Date: Sun, 3 Dec 2017 11:33:17 +0900 Subject: [PATCH] Truncate too long assertion messages --- lib/power_assert/context.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/power_assert/context.rb b/lib/power_assert/context.rb index 2a82f05..fbe380d 100644 --- a/lib/power_assert/context.rb +++ b/lib/power_assert/context.rb @@ -6,6 +6,7 @@ module PowerAssert class Context Value = Struct.new(:name, :value, :lineno, :column) + MAX_LINE_LENGTH = 500 def initialize(base_caller_length) @fired = false @@ -92,12 +93,17 @@ def build_assertion_message(parser, return_values) map_to = vals.each_with_object({}) do |j, h| h[j.column.to_s.to_sym] = [l, '|', ' '][i.column <=> j.column] end - lines << encoding_safe_rstrip(sprintf(fmt, map_to)) + line = encoding_safe_rstrip(sprintf(fmt, map_to)) + lines << truncate(line, MAX_LINE_LENGTH) end end lines.join("\n") end + def truncate(line, length) + "#{line[0..length]}#{'...' if line.size > length}" + end + def detect_path(parser, return_values) return parser.call_paths.flatten.uniq if parser.method_id_set.empty? all_paths = parser.call_paths