diff --git a/lib/cucumber/formatter/interceptor.rb b/lib/cucumber/formatter/interceptor.rb index 07bb150360..ae3f3678f1 100644 --- a/lib/cucumber/formatter/interceptor.rb +++ b/lib/cucumber/formatter/interceptor.rb @@ -8,7 +8,7 @@ class Pipe attr_reader :pipe def initialize(pipe) @pipe = pipe - @buffer = [] + @buffer = StringIO.new @wrapped = true end @@ -19,9 +19,21 @@ def write(str) end end + # @deprecated use #buffer_string def buffer + require 'cucumber/deprecate.rb' + Cucumber.deprecate( + 'Use Cucumber::Formatter::Interceptor::Pipe#buffer_string instead', + 'Cucumber::Formatter::Interceptor::Pipe#buffer', + '3.99') lock.synchronize do - return @buffer.dup + return @buffer.string.lines + end + end + + def buffer_string + lock.synchronize do + return @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 diff --git a/spec/cucumber/formatter/junit_spec.rb b/spec/cucumber/formatter/junit_spec.rb index 91fabf1696..6160640991 100644 --- a/spec/cucumber/formatter/junit_spec.rb +++ b/spec/cucumber/formatter/junit_spec.rb @@ -66,6 +66,29 @@ def write_file(feature_filename, data) it { expect(@doc.xpath('//testsuite/testcase/system-out').first.content).to match(/\s+boo boo\s+/) } end + describe 'is able to handle multiple encodings in pipe' do + before(:each) do + run_defined_feature + @doc = Nokogiri.XML(@formatter.written_files.values.first) + end + + define_steps do + Given(/a passing ctrl scenario/) do + Kernel.puts "encoding" + Kernel.puts "pickle".encode("UTF-16") + end + end + + define_feature " + Feature: One passing scenario, one failing scenario + + Scenario: Passing + Given a passing ctrl scenario + " + + it { expect(@doc.xpath('//testsuite/testcase/system-out').first.content).to match(/\s+encoding\npickle\s+/) } + end + describe 'a feature with no name' do define_feature <<-FEATURE Feature: