From 0a208e843df977da8d81266894514fdbb867963c Mon Sep 17 00:00:00 2001 From: Nick Abalov Date: Sun, 14 Jan 2018 19:31:55 +0000 Subject: [PATCH 1/3] Add test for handling captured output encodings in junit --- spec/cucumber/formatter/junit_spec.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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: From 1a7612b6504dd5b9bd100ad13825628677486583 Mon Sep 17 00:00:00 2001 From: Nick Abalov Date: Sun, 14 Jan 2018 19:39:18 +0000 Subject: [PATCH 2/3] Fix incompatible encodings error in junit formatter --- lib/cucumber/formatter/interceptor.rb | 11 +++++++++-- lib/cucumber/formatter/junit.rb | 4 ++-- spec/cucumber/formatter/interceptor_spec.rb | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/cucumber/formatter/interceptor.rb b/lib/cucumber/formatter/interceptor.rb index 07bb150360..694ca08a75 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,16 @@ def write(str) end end + # @deprecated use #buffer_string def buffer 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 From 0cc6a781456a27c1578dffc1ff1abeb1524287b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Rasmusson?= Date: Sat, 20 Jan 2018 20:28:24 +0100 Subject: [PATCH 3/3] Add deprecation warning for Interceptor::Pipe#buffer. --- lib/cucumber/formatter/interceptor.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/cucumber/formatter/interceptor.rb b/lib/cucumber/formatter/interceptor.rb index 694ca08a75..ae3f3678f1 100644 --- a/lib/cucumber/formatter/interceptor.rb +++ b/lib/cucumber/formatter/interceptor.rb @@ -21,6 +21,11 @@ def write(str) # @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.string.lines end