Skip to content

Commit

Permalink
Don't raise exception on JRuby 9k < 9.2.1.0
Browse files Browse the repository at this point in the history
JRuby 9k 9.2.0.0 and lower will has a bug in Ripper.sexp that raises a
NoMethodError when analyzing code that even references a method with
keyword arguments. This makes failure formatting raise that exception.
Best to just not use Ripper on JRuby 9k < 9.2.1.0.

[Fixes #399]
  • Loading branch information
BrianHawley committed Jan 24, 2020
1 parent 407bfa8 commit 39de8fb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/rspec/support/ruby_features.rb
Expand Up @@ -111,7 +111,8 @@ def supports_taint?
ripper_requirements.push(Ruby.jruby_version >= '1.7.5')
# Ripper on JRuby 9.0.0.0.rc1 - 9.1.8.0 reports wrong line number
# or cannot parse source including `:if`.
ripper_requirements.push(!Ruby.jruby_version.between?('9.0.0.0.rc1', '9.1.8.0'))
# Ripper on JRuby 9.x.x.x < 9.2.1.0 can't handle keyword arguments.
ripper_requirements.push(!Ruby.jruby_version.between?('9.0.0.0.rc1', '9.2.0.0'))
end

if ripper_requirements.all?
Expand Down
22 changes: 21 additions & 1 deletion spec/rspec/support/ruby_features_spec.rb
Expand Up @@ -120,7 +120,8 @@ def ripper_is_implemented?

def ripper_works_correctly?
ripper_reports_correct_line_number? &&
ripper_can_parse_source_including_keywordish_symbol?
ripper_can_parse_source_including_keywordish_symbol? &&
ripper_can_parse_source_referencing_keyword_arguments?
end

# https://github.com/jruby/jruby/issues/3386
Expand All @@ -144,6 +145,25 @@ def ripper_can_parse_source_including_keywordish_symbol?
end
end

# https://github.com/jruby/jruby/issues/5209
def ripper_can_parse_source_referencing_keyword_arguments?
in_sub_process_if_possible do
require 'ripper'
# It doesn't matter if keyword arguments don't exist.
if Ruby.mri? || Ruby.jruby?
if RUBY_VERSION < '2.0'
true
else
begin
!::Ripper.sexp('def a(**kw_args); end').nil?
rescue NoMethodError
false
end
end
end
end
end

it 'returns whether Ripper is correctly implemented in the current environment' do
expect(RubyFeatures.ripper_supported?).to eq(ripper_is_implemented? && ripper_works_correctly?)
end
Expand Down

0 comments on commit 39de8fb

Please sign in to comment.