lib/cucumber/formatter/console.rb in cucumber-6.1.0 vs lib/cucumber/formatter/console.rb in cucumber-7.0.0
- old
+ new
@@ -32,11 +32,11 @@
extend ANSIColor
include Duration
def format_step(keyword, step_match, status, source_indent)
comment = if source_indent
- c = ('# ' + step_match.location.to_s).indent(source_indent)
+ c = indent(('# ' + step_match.location.to_s), source_indent)
format_string(c, :comment)
else
''
end
@@ -97,15 +97,15 @@
def print_exception(e, status, indent)
string = exception_message_string(e, indent)
@io.puts(format_string(string, status))
end
- def exception_message_string(e, indent)
+ def exception_message_string(e, indent_amount)
message = "#{e.message} (#{e.class})".dup.force_encoding('UTF-8')
message = linebreaks(message, ENV['CUCUMBER_TRUNCATE_OUTPUT'].to_i)
- "#{message}\n#{e.backtrace.join("\n")}".indent(indent)
+ indent("#{message}\n#{e.backtrace.join("\n")}", indent_amount)
end
# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/10655
def linebreaks(msg, max)
return msg unless max && max > 0
@@ -204,9 +204,17 @@
' # or just one if there are none.',
" transformer: ->(s) { #{camelized}.new(s) }",
')',
''
].join("\n")
+ end
+
+ def indent(string, padding)
+ if padding >= 0
+ string.gsub(/^/, ' ' * padding)
+ else
+ string.gsub(/^ {0,#{-padding}}/, '')
+ end
end
private
FORMATS = Hash.new { |hash, format| hash[format] = method(format).to_proc }