Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incompatible encodings error in Junit formatter #1244

Merged
merged 3 commits into from
Jan 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions lib/cucumber/formatter/interceptor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Pipe
attr_reader :pipe
def initialize(pipe)
@pipe = pipe
@buffer = []
@buffer = StringIO.new
@wrapped = true
end

Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/cucumber/formatter/junit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/cucumber/formatter/interceptor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 23 additions & 0 deletions spec/cucumber/formatter/junit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down