Skip to content

Commit

Permalink
Merge pull request #400 from BrianHawley/fixes_399
Browse files Browse the repository at this point in the history
Don't raise exception on JRuby 9k < 9.2.1.0
  • Loading branch information
JonRowe committed Jan 25, 2020
2 parents 407bfa8 + 39de8fb commit 57989b8
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 57989b8

Please sign in to comment.