Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 79a65ee

Browse files
committed
Don't raise exception on JRuby 9k < 9.2.1.0
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]
1 parent 407bfa8 commit 79a65ee

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/rspec/support/ruby_features.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ def supports_taint?
111111
ripper_requirements.push(Ruby.jruby_version >= '1.7.5')
112112
# Ripper on JRuby 9.0.0.0.rc1 - 9.1.8.0 reports wrong line number
113113
# or cannot parse source including `:if`.
114-
ripper_requirements.push(!Ruby.jruby_version.between?('9.0.0.0.rc1', '9.1.8.0'))
114+
# Ripper on JRuby 9.x.x.x < 9.2.1.0 can't handle keyword arguments.
115+
ripper_requirements.push(!Ruby.jruby_version.between?('9.0.0.0.rc1', '9.2.0.0'))
115116
end
116117

117118
if ripper_requirements.all?

spec/rspec/support/ruby_features_spec.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ def ripper_is_implemented?
120120

121121
def ripper_works_correctly?
122122
ripper_reports_correct_line_number? &&
123-
ripper_can_parse_source_including_keywordish_symbol?
123+
ripper_can_parse_source_including_keywordish_symbol? &&
124+
ripper_can_parse_source_referencing_keyword_arguments?
124125
end
125126

126127
# https://github.com/jruby/jruby/issues/3386
@@ -144,6 +145,18 @@ def ripper_can_parse_source_including_keywordish_symbol?
144145
end
145146
end
146147

148+
# https://github.com/jruby/jruby/issues/5209
149+
def ripper_can_parse_source_referencing_keyword_arguments?
150+
in_sub_process_if_possible do
151+
require 'ripper'
152+
begin
153+
!::Ripper.sexp('def a(**kw_args); end').nil?
154+
rescue
155+
false
156+
end
157+
end
158+
end
159+
147160
it 'returns whether Ripper is correctly implemented in the current environment' do
148161
expect(RubyFeatures.ripper_supported?).to eq(ripper_is_implemented? && ripper_works_correctly?)
149162
end

0 commit comments

Comments
 (0)