From 22589c87c61fc756eb85f10c9f01ef7c5125e22d Mon Sep 17 00:00:00 2001 From: Nick Abalov Date: Sun, 14 Jan 2018 19:39:18 +0000 Subject: [PATCH] Fix incompatible encodings error in junit formatter --- lib/cucumber/formatter/interceptor.rb | 13 ++++++++++--- lib/cucumber/formatter/junit.rb | 4 ++-- spec/cucumber/formatter/interceptor_spec.rb | 1 + 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/cucumber/formatter/interceptor.rb b/lib/cucumber/formatter/interceptor.rb index 07bb150360..9f4e4505c0 100644 --- a/lib/cucumber/formatter/interceptor.rb +++ b/lib/cucumber/formatter/interceptor.rb @@ -8,20 +8,27 @@ class Pipe attr_reader :pipe def initialize(pipe) @pipe = pipe - @buffer = [] + @string_buffer = StringIO.new @wrapped = true end def write(str) lock.synchronize do - @buffer << str if @wrapped + @string_buffer << str if @wrapped return @pipe.write(str) end end + # @deprecated use #buffer_string def buffer lock.synchronize do - return @buffer.dup + return @string_buffer.string.lines + end + end + + def buffer_string + lock.synchronize do + return @string_buffer.string.dup end end diff --git a/lib/cucumber/formatter/junit.rb b/lib/cucumber/formatter/junit.rb index 24f30d163a..3daacf6172 100644 --- a/lib/cucumber/formatter/junit.rb +++ b/lib/cucumber/formatter/junit.rb @@ -140,10 +140,10 @@ def build_testcase(result, scenario_designation, output) @current_feature_data[:failures] += 1 end @current_feature_data[:builder].tag!('system-out') do - @current_feature_data[:builder].cdata! strip_control_chars(@interceptedout.buffer.join) + @current_feature_data[:builder].cdata! strip_control_chars(@interceptedout.buffer_string) end @current_feature_data[:builder].tag!('system-err') do - @current_feature_data[:builder].cdata! strip_control_chars(@interceptederr.buffer.join) + @current_feature_data[:builder].cdata! strip_control_chars(@interceptederr.buffer_string) end end @current_feature_data[:tests] += 1 diff --git a/spec/cucumber/formatter/interceptor_spec.rb b/spec/cucumber/formatter/interceptor_spec.rb index 006534534e..1202327237 100644 --- a/spec/cucumber/formatter/interceptor_spec.rb +++ b/spec/cucumber/formatter/interceptor_spec.rb @@ -114,6 +114,7 @@ module Cucumber::Formatter expect(pi.buffer).not_to be_empty expect(pi.buffer.first).to eq buffer + expect(pi.buffer_string).to eq buffer end end