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

Commit 6042ee1

Browse files
committed
Add RubyFeatures.ripper_supported?
1 parent 01a65c2 commit 6042ee1

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Enhancements:
55
* Improve formatting of `Delegator` based objects (e.g. `SimpleDelgator`) in
66
failure messages and diffs. (Andrew Horner, #215)
77
* Add `ComparableVersion`. (Yuji Nakayama, #245)
8+
* Add `Ripper` support detection. (Yuji Nakayama, #245)
89

910
Bug Fixes:
1011

benchmarks/ripper.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
require 'benchmark/ips'
2+
require 'ripper'
3+
4+
ruby_version = defined?(JRUBY_VERSION) ? JRUBY_VERSION : RUBY_VERSION
5+
puts "#{RUBY_ENGINE} #{ruby_version}"
6+
7+
source = File.read(__FILE__)
8+
9+
Benchmark.ips do |x|
10+
x.report("Ripper") do
11+
Ripper.sexp(source)
12+
Ripper.lex(source)
13+
end
14+
end
15+
16+
__END__
17+
18+
ruby 1.9.3
19+
Calculating -------------------------------------
20+
Ripper 284.000 i/100ms
21+
22+
ruby 2.2.3
23+
Calculating -------------------------------------
24+
Ripper 320.000 i/100ms
25+
26+
jruby 1.7.5
27+
Calculating -------------------------------------
28+
Ripper 24.000 i/100ms
29+
30+
jruby 1.7.13
31+
Calculating -------------------------------------
32+
Ripper 25.000 i/100ms
33+
34+
jruby 1.7.14
35+
Calculating -------------------------------------
36+
Ripper 239.000 i/100ms
37+
38+
jruby 1.7.22
39+
Calculating -------------------------------------
40+
Ripper 231.000 i/100ms
41+
42+
jruby 9.0.1.0
43+
Calculating -------------------------------------
44+
Ripper 218.000 i/100ms

lib/rspec/support/ruby_features.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'rbconfig'
2+
RSpec::Support.require_rspec_support "comparable_version"
23

34
module RSpec
45
module Support
@@ -65,6 +66,24 @@ def supports_exception_cause?
6566
end
6667
end
6768

69+
ripper_requirements = [ComparableVersion.new(RUBY_VERSION) >= '1.9.2']
70+
71+
if Ruby.jruby?
72+
ripper_requirements.push(ComparableVersion.new(JRUBY_VERSION) >= '1.7.5')
73+
# Ripper on JRuby 9.0.0.0.rc1 or later reports wrong line number.
74+
ripper_requirements.push(ComparableVersion.new(JRUBY_VERSION) < '9.0.0.0.rc1')
75+
end
76+
77+
if ripper_requirements.all?
78+
def ripper_supported?
79+
true
80+
end
81+
else
82+
def ripper_supported?
83+
false
84+
end
85+
end
86+
6887
if Ruby.mri?
6988
def kw_args_supported?
7089
RUBY_VERSION >= '2.0.0'

spec/rspec/support/ruby_features_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ module Support
8181
expect(RubyFeatures.caller_locations_supported?).to eq(RUBY_VERSION >= '2.0.0')
8282
end
8383
end
84+
85+
describe "#ripper_supported?" do
86+
it 'does not load Ripper' do
87+
expect { RubyFeatures.ripper_supported? }.not_to change { defined?(::Ripper) }
88+
end
89+
end
8490
end
8591
end
8692
end

0 commit comments

Comments
 (0)