Skip to content

Commit

Permalink
Merge #1244 'Fix incompatible encodings error in JUnit formatter'
Browse files Browse the repository at this point in the history
Also update Changelog.md.
  • Loading branch information
brasmusson committed Jan 21, 2018
2 parents aab3969 + 0cc6a78 commit dadf088
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down
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 @@ -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
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 @@ -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

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

2 comments on commit dadf088

@mxygem
Copy link
Member

@mxygem mxygem commented on dadf088 Jan 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brasmusson Any idea why this merge seems to have broken our jruby Circle build?

@mxygem
Copy link
Member

@mxygem mxygem commented on dadf088 Jan 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1) Cucumber::Formatter::Junit With no options is able to handle multiple encodings in pipe 
     Failure/Error: cdata.scan(/[[:print:]\t\n\r]/).join
     
     ArgumentError:
       Failed describing child of #<Cucumber::Core::Ast::Feature "Feature: One passing scenario, one failing scenario" (spec.feature:2)> - invalid byte sequence in UTF-8
     # ./lib/cucumber/formatter/junit.rb:181:in `strip_control_chars'
     # ./lib/cucumber/formatter/junit.rb:144:in `block in build_testcase'
     # ./vendor/bundle/jruby/2.3.0/gems/builder-3.2.3/lib/builder/xmlbase.rb:175:in `_nested_structures'
     # ./vendor/bundle/jruby/2.3.0/gems/builder-3.2.3/lib/builder/xmlbase.rb:68:in `tag!'
     # ./lib/cucumber/formatter/junit.rb:143:in `block in build_testcase'
     # ./vendor/bundle/jruby/2.3.0/gems/builder-3.2.3/lib/builder/xmlbase.rb:175:in `_nested_structures'
     # ./vendor/bundle/jruby/2.3.0/gems/builder-3.2.3/lib/builder/xmlbase.rb:68:in `tag!'
     # ./vendor/bundle/jruby/2.3.0/gems/builder-3.2.3/lib/builder/xmlbase.rb:93:in `method_missing'
     # ./lib/cucumber/formatter/junit.rb:130:in `build_testcase'
     # ./lib/cucumber/formatter/junit.rb:66:in `on_test_case_finished'
     # ./vendor/bundle/jruby/2.3.0/gems/cucumber-core-3.1.0/lib/cucumber/core/event_bus.rb:34:in `block in broadcast'
     # ./vendor/bundle/jruby/2.3.0/gems/cucumber-core-3.1.0/lib/cucumber/core/event_bus.rb:34:in `broadcast'
     # ./vendor/bundle/jruby/2.3.0/gems/cucumber-core-3.1.0/lib/cucumber/core/event_bus.rb:40:in `method_missing'
     # ./vendor/bundle/jruby/2.3.0/gems/cucumber-core-3.1.0/lib/cucumber/core/test/runner.rb:20:in `test_case'
     # ./vendor/bundle/jruby/2.3.0/gems/cucumber-core-3.1.0/lib/cucumber/core/test/case.rb:25:in `describe_to'
     # ./lib/cucumber/filters/prepare_world.rb:12:in `test_case'
     # ./vendor/bundle/jruby/2.3.0/gems/cucumber-core-3.1.0/lib/cucumber/core/test/case.rb:25:in `describe_to'
     # ./lib/cucumber/filters/apply_around_hooks.rb:9:in `test_case'
     # ./vendor/bundle/jruby/2.3.0/gems/cucumber-core-3.1.0/lib/cucumber/core/test/case.rb:25:in `describe_to'
     # ./lib/cucumber/filters/apply_after_hooks.rb:6:in `test_case'
     # ./vendor/bundle/jruby/2.3.0/gems/cucumber-core-3.1.0/lib/cucumber/core/test/case.rb:25:in `describe_to'
     # ./lib/cucumber/filters/apply_before_hooks.rb:6:in `test_case'
     # ./vendor/bundle/jruby/2.3.0/gems/cucumber-core-3.1.0/lib/cucumber/core/test/case.rb:25:in `describe_to'
     # ./lib/cucumber/filters/apply_after_step_hooks.rb:9:in `test_case'
     # ./vendor/bundle/jruby/2.3.0/gems/cucumber-core-3.1.0/lib/cucumber/core/test/case.rb:25:in `describe_to'
     # ./lib/cucumber/filters/activate_steps.rb:12:in `test_case'
     # ./vendor/bundle/jruby/2.3.0/gems/cucumber-core-3.1.0/lib/cucumber/core/test/case.rb:25:in `describe_to'
     # ./vendor/bundle/jruby/2.3.0/gems/cucumber-core-3.1.0/lib/cucumber/core/compiler.rb:48:in `on_test_case'
     # ./vendor/bundle/jruby/2.3.0/gems/cucumber-core-3.1.0/lib/cucumber/core/compiler.rb:90:in `scenario'
     # ./vendor/bundle/jruby/2.3.0/gems/cucumber-core-3.1.0/lib/cucumber/core/ast/describes_itself.rb:7:in `describe_to'
     # ./vendor/bundle/jruby/2.3.0/gems/cucumber-core-3.1.0/lib/cucumber/core/ast/describes_itself.rb:10:in `block in describe_to'
     # ./vendor/bundle/jruby/2.3.0/gems/cucumber-core-3.1.0/lib/cucumber/core/ast/describes_itself.rb:8:in `block in describe_to'
     # ./vendor/bundle/jruby/2.3.0/gems/cucumber-core-3.1.0/lib/cucumber/core/compiler.rb:75:in `feature'
     # ./vendor/bundle/jruby/2.3.0/gems/cucumber-core-3.1.0/lib/cucumber/core/ast/describes_itself.rb:7:in `describe_to'
     # ./vendor/bundle/jruby/2.3.0/gems/cucumber-core-3.1.0/lib/cucumber/core/compiler.rb:19:in `feature'
     # ./vendor/bundle/jruby/2.3.0/gems/cucumber-core-3.1.0/lib/cucumber/core/gherkin/parser.rb:30:in `document'
     # ./vendor/bundle/jruby/2.3.0/gems/cucumber-core-3.1.0/lib/cucumber/core.rb:30:in `block in parse'
     # ./vendor/bundle/jruby/2.3.0/gems/cucumber-core-3.1.0/lib/cucumber/core.rb:29:in `parse'
     # ./vendor/bundle/jruby/2.3.0/gems/cucumber-core-3.1.0/lib/cucumber/core.rb:21:in `compile'
     # ./spec/cucumber/formatter/spec_helper.rb:37:in `run_defined_feature'
     # ./spec/cucumber/formatter/junit_spec.rb:71:in `block in Formatter'
     # ------------------
     # --- Caused by: ---
     # ArgumentError:
     #   invalid byte sequence in UTF-8
     #   ./lib/cucumber/formatter/junit.rb:181:in `strip_control_chars'

Finished in 20.78 seconds (files took 5.73 seconds to load)
562 examples, 1 failure, 1 pending

Failed examples:

rspec ./spec/cucumber/formatter/junit_spec.rb:89 # Cucumber::Formatter::Junit With no options is able to handle multiple encodings in pipe 

Please sign in to comment.