From 88aee8b2006cf3098c06f14ade80b99482bc4bd3 Mon Sep 17 00:00:00 2001 From: Brandon Fish Date: Fri, 10 Jan 2020 10:48:07 -0600 Subject: [PATCH] Update ripper_supported? for truffleruby and ripper specs to allow exceptions --- lib/rspec/support/ruby_features.rb | 6 +++++- spec/rspec/support/ruby_features_spec.rb | 26 ++++++++++++++++-------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/rspec/support/ruby_features.rb b/lib/rspec/support/ruby_features.rb index 20e58075a..ea4033df6 100644 --- a/lib/rspec/support/ruby_features.rb +++ b/lib/rspec/support/ruby_features.rb @@ -47,6 +47,10 @@ def non_mri? def mri? !defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby' end + + def truffleruby? + defined?(RUBY_ENGINE) && RUBY_ENGINE == 'truffleruby' + end end # @api private @@ -101,7 +105,7 @@ def supports_taint? end ripper_requirements = [ComparableVersion.new(RUBY_VERSION) >= '1.9.2'] - ripper_requirements.push(false) if Ruby.rbx? + ripper_requirements.push(false) if Ruby.rbx? || Ruby.truffleruby? if Ruby.jruby? ripper_requirements.push(Ruby.jruby_version >= '1.7.5') diff --git a/spec/rspec/support/ruby_features_spec.rb b/spec/rspec/support/ruby_features_spec.rb index 10fc1525e..8d81bd914 100644 --- a/spec/rspec/support/ruby_features_spec.rb +++ b/spec/rspec/support/ruby_features_spec.rb @@ -126,21 +126,29 @@ def ripper_works_correctly? # https://github.com/jruby/jruby/issues/3386 def ripper_reports_correct_line_number? in_sub_process_if_possible do - require 'ripper' - tokens = ::Ripper.lex('foo') - token = tokens.first - location = token.first - line_number = location.first - line_number == 1 + begin + require 'ripper' + tokens = ::Ripper.lex('foo') + token = tokens.first + location = token.first + line_number = location.first + line_number == 1 + rescue + false + end end end # https://github.com/jruby/jruby/issues/4562 def ripper_can_parse_source_including_keywordish_symbol? in_sub_process_if_possible do - require 'ripper' - sexp = ::Ripper.sexp(':if') - !sexp.nil? + begin + require 'ripper' + sexp = ::Ripper.sexp(':if') + !sexp.nil? + rescue + false + end end end