Skip to content

Commit 512d598

Browse files
committed
gem_install_unless_installed fix on newer rubygems (>= 2.3.0) - still not as expected ;(
1 parent 3c4bfef commit 512d598

File tree

3 files changed

+28
-20
lines changed

3 files changed

+28
-20
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
source "https://rubygems.org"
1+
source 'https://rubygems.org'
22

33
group :default do
44
if rack_version = ENV['RACK_VERSION']

src/spec/ruby/rack/application_spec.rb

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,10 @@ def newRuntime() # use the current runtime instead of creating new
311311
end
312312

313313
it "loads specified version of rack", :lib => :stub do
314-
gem_install_rack_unless_installed '1.3.10'
314+
gem_install_unless_installed 'rack', '1.3.10'
315315
set_config 'jruby.runtime.env', 'false'
316316

317-
script = "" +
318-
"# rack.version: ~>1.3.6\n" +
319-
"Proc.new { 'proc-rack-app' }"
317+
script = "# rack.version: ~>1.3.6\n Proc.new { 'proc-rack-app' }"
320318
app_factory.setRackupScript script
321319
@runtime = app_factory.newRuntime
322320
@runtime.evalScriptlet "ENV['GEM_HOME'] = #{ENV['GEM_HOME'].inspect}"
@@ -330,7 +328,7 @@ def newRuntime() # use the current runtime instead of creating new
330328
end
331329

332330
it "loads bundler with rack", :lib => :stub do
333-
gem_install_rack_unless_installed '1.3.6'
331+
gem_install_unless_installed 'rack', '1.3.6'
334332
set_config 'jruby.runtime.env', 'false'
335333

336334
script = "# encoding: UTF-8\n" +
@@ -354,20 +352,6 @@ def newRuntime() # use the current runtime instead of creating new
354352
should_eval_as_eql_to "Gem.loaded_specs['rack'].version.to_s", '1.3.6'
355353
end
356354

357-
def gem_install_rack_unless_installed(version)
358-
begin
359-
if Gem::Specification.respond_to? :find_by_name
360-
Gem::Specification.find_by_name 'rack', version
361-
else
362-
raise Gem::LoadError unless Gem.available? 'rack', version
363-
end
364-
rescue Gem::LoadError
365-
require 'rubygems/dependency_installer'
366-
installer = Gem::DependencyInstaller.new
367-
installer.install 'rack', version
368-
end
369-
end
370-
371355
# should not matter on 1.7.x due https://github.com/jruby/jruby/pull/123
372356
if JRUBY_VERSION < '1.7.0'
373357
it "does not load any features (until load path is adjusted)" do

src/spec/ruby/spec_helper.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,30 @@ def raise_logger(level = 'WARN')
8484
org.jruby.rack.logging.RaiseLogger.new(level, JRuby.runtime.out)
8585
end
8686

87+
def gem_install_unless_installed(name, version)
88+
found = nil
89+
begin
90+
if Gem::Specification.respond_to? :find_all
91+
all = Gem::Specification.find_all
92+
found = all.find do |spec|
93+
spec.name == name && spec.version.to_s == version
94+
end
95+
elsif Gem::Specification.respond_to? :find_by_name
96+
found = Gem::Specification.find_by_name name, version
97+
else
98+
raise Gem::LoadError unless Gem.available? name, version
99+
end
100+
rescue Gem::LoadError
101+
found = false
102+
end
103+
# NOTE: won't ever be found in RubyGems >= 2.3 likely due Bundler
104+
unless found
105+
require 'rubygems/dependency_installer'
106+
installer = Gem::DependencyInstaller.new
107+
installer.install name, version
108+
end
109+
end
110+
87111
ExpectationNotMetError = RSpec::Expectations::ExpectationNotMetError
88112

89113
def expect_eql_java_bytes(actual, expected)

0 commit comments

Comments
 (0)