From 0381d1bb28ef2fc68b759787b6ed1f9b671c83c4 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Wed, 13 Jan 2021 14:50:35 +0900 Subject: [PATCH] Workaround for JRuby 9.2.14.0 This commit a workaround to prevent the following JRuby error. ```console % ruby -v jruby 9.2.14.0 (2.5.7) 2020-12-08 ebe64bafb9 Java HotSpot(TM) 64-Bit Server VM 25.271-b09 on 1.8.0_271-b09 +jit [darwin-x86_64] % bundle exec rake ascii_spec (snip) Failures: 1) RuboCop::CLI --show-cops with no args prints all cops in their right department listing Failure/Error: lines.slice_before(/Department /).each do |slice| departments = registry.departments.map(&:to_s) current = departments.delete(slice.shift[/Department '(?[^']+)'/, 'c']) # all cops in their department listing registry.with_department(current).each do |cop| expect(slice.any? { |l| l.include? cop.cop_name }).to be_truthy end ArgumentError: invalid byte sequence in US-ASCII # uri:classloader:/jruby/kernel/enumerable.rb:17:in `block in slice_before' # uri:classloader:/jruby/kernel/enumerable.rb:9:in `block in slice_before' # ./spec/rubocop/cli/cli_options_spec.rb:1136:in `block in
' # ./spec/support/cli_spec_behavior.rb:27:in `block in /Users/koic/src/github.com/rubocop-hq/rubocop/spec/support/cli_spec_behavior.rb' # ./lib/rubocop/rspec/shared_contexts.rb:31:in `block in /Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/rspec/shared_contexts.rb' # ./lib/rubocop/rspec/shared_contexts.rb:30:in `block in /Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/rspec/shared_contexts.rb' # ./lib/rubocop/rspec/shared_contexts.rb:7:in `block in /Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/rspec/shared_contexts.rb' Finished in 3 minutes 1.3 seconds (files took 7.47 seconds to load) 114 examples, 1 failure Failed examples: rspec ./spec/rubocop/cli/cli_options_spec.rb:1134 # RuboCop::CLI --show-cops with no args prints all cops in their right department listing ``` https://app.circleci.com/pipelines/github/rubocop-hq/rubocop/3729/workflows/d5c1759d-0727-4db1-82ff-4413e446ed87/jobs/166685 See: https://github.com/jruby/jruby/issues/6528 --- spec/rubocop/cli/cli_options_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/rubocop/cli/cli_options_spec.rb b/spec/rubocop/cli/cli_options_spec.rb index 258d31f5a392..de18c4b3dd21 100644 --- a/spec/rubocop/cli/cli_options_spec.rb +++ b/spec/rubocop/cli/cli_options_spec.rb @@ -1181,6 +1181,11 @@ def full_description_of_cop(cop) it 'prints all cops in their right department listing' do lines = stdout.lines + # FIXME: Remove the following workaround condition for JRuby. + # https://github.com/jruby/jruby/issues/6528 + if RUBY_ENGINE == 'jruby' && Encoding.default_external == Encoding::ASCII + lines = lines.select(&:valid_encoding?) + end lines.slice_before(/Department /).each do |slice| departments = registry.departments.map(&:to_s) current =