diff --git a/CHANGELOG.md b/CHANGELOG.md index 02bd6c50b5..333b8ed9a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,6 @@ Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blo ### Changed -* Fix Layout/EmptyLineBetweenDefs ([#1257](https://github.com/cucumber/cucumber-ruby/pull/1257) [@jaysonesmith](https://github.com/jaysonesmith)) * N/A ### Deprecated @@ -31,10 +30,12 @@ Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blo ### Fixed +* Fix incompatible encodings error in JUnit formatter ([#1244](https://github.com/cucumber/cucumber-ruby/pull/1244) [@NickAb](https://github.com/NickAb)) * Fix the handling of failed hooks in the JUnit Formatter ([@brasmusson](https://github.com/brasmusson)) ### Improved +* Fix Layout/EmptyLineBetweenDefs ([#1257](https://github.com/cucumber/cucumber-ruby/pull/1257) [@jaysonesmith](https://github.com/jaysonesmith)) * Fix Bundler/OrderedGems ([#1250](https://github.com/cucumber/cucumber-ruby/pull/1250) [@jaysonesmith](https://github.com/jaysonesmith)) * Update Rubocop version to 0.52.1 and redo rubocop_todo.yml ([#1246](https://github.com/cucumber/cucumber-ruby/pull/1246) [@jaysonesmith](https://github.com/jaysonesmith)) * Fix Style/BlockDelimiters ([#1224](https://github.com/cucumber/cucumber-ruby/pull/1224) [@jaysonesmith](https://github.com/jaysonesmith)) 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 a0da7ea661..1e7d33a3c5 100644 --- a/lib/cucumber/formatter/junit.rb +++ b/lib/cucumber/formatter/junit.rb @@ -141,10 +141,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 4f30ef60f8..5c4d607815 100644 --- a/spec/cucumber/formatter/interceptor_spec.rb +++ b/spec/cucumber/formatter/interceptor_spec.rb @@ -110,6 +110,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 514a2bc109..16a73fd43c 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: