Skip to content

Commit 39cdba5

Browse files
committed
Correct application specs for later JRubies
- removes exception unwrapping workarounds - removes JRuby 1.6 specific specs - tests RUBYOPT with a supported flag on modern Ruby Signed-off-by: Chad Wilson <[email protected]>
1 parent b5d1bc6 commit 39cdba5

File tree

2 files changed

+10
-77
lines changed

2 files changed

+10
-77
lines changed

src/spec/ruby/rack/application_spec.rb

Lines changed: 10 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def it_should_rewind_body
170170
$servlet_context = @servlet_context
171171
# NOTE: a workaround to be able to mock it :
172172
klass = Class.new(DefaultRackApplicationFactory) do
173-
def createRackServletWrapper(runtime, rackup); end
173+
def createRackServletWrapper(runtime, rackup, filename); end
174174
end
175175
@app_factory = klass.new
176176

@@ -311,10 +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_unless_installed 'rack', '2.1.4'
314+
gem_install_unless_installed 'rack', '1.3.10'
315315
set_config 'jruby.runtime.env', 'false'
316316

317-
script = "# rack.version: ~>2.1.0\n Proc.new { 'proc-rack-app' }"
317+
script = "# rack.version: ~>1.3.6\n Proc.new { 'proc-rack-app' }"
318318
app_factory.setRackupScript script
319319
@runtime = app_factory.newRuntime
320320
@runtime.evalScriptlet "ENV['GEM_HOME'] = #{ENV['GEM_HOME'].inspect}"
@@ -323,8 +323,8 @@ def newRuntime() # use the current runtime instead of creating new
323323
app_factory.checkAndSetRackVersion(@runtime)
324324
@runtime.evalScriptlet "require 'rack'"
325325

326-
should_eval_as_eql_to "Rack.release if defined? Rack.release", '2.1'
327-
should_eval_as_eql_to "Gem.loaded_specs['rack'].version.to_s", '2.1.4'
326+
should_eval_as_eql_to "Rack.release if defined? Rack.release", '1.3'
327+
should_eval_as_eql_to "Gem.loaded_specs['rack'].version.to_s", '1.3.10'
328328
end
329329

330330
it "loads bundler with rack", :lib => :stub do
@@ -338,7 +338,7 @@ def newRuntime() # use the current runtime instead of creating new
338338
@runtime = app_factory.newRuntime
339339

340340
file = Tempfile.new('Gemfile')
341-
file << "source 'http://rubygems.org'\n gem 'rack', '1.3.6'"
341+
file << "source 'https://rubygems.org'\n gem 'rack', '1.3.6'"
342342
file.flush
343343
@runtime.evalScriptlet "ENV['BUNDLE_GEMFILE'] = #{file.path.inspect}"
344344
@runtime.evalScriptlet "ENV['GEM_HOME'] = #{ENV['GEM_HOME'].inspect}"
@@ -352,57 +352,6 @@ def newRuntime() # use the current runtime instead of creating new
352352
should_eval_as_eql_to "Gem.loaded_specs['rack'].version.to_s", '1.3.6'
353353
end
354354

355-
# should not matter on 1.7.x due https://github.com/jruby/jruby/pull/123
356-
if JRUBY_VERSION < '1.7.0'
357-
it "does not load any features (until load path is adjusted)" do
358-
set_runtime_environment("false")
359-
# due to incorrectly detected jruby.home some container e.g. WebSphere 8
360-
# fail if things such as 'fileutils' get required during runtime init !
361-
362-
# TODO: WTF? JRuby magic - $LOADED_FEATURES seems to get "inherited" if
363-
# Ruby.newInstance(config) is called with the factory's defaultConfig,
364-
# but only if it's executed with bundler e.g. `bundle exec rake spec`
365-
#@runtime = app_factory.new_runtime
366-
@runtime = org.jruby.Ruby.newInstance
367-
app_factory.send :initRuntime, @runtime
368-
369-
#@runtime.evalScriptlet 'puts "initRuntime $LOADED_FEATURES: #{$LOADED_FEATURES.inspect}"'
370-
# NOTE: the above scriptlet behaves slightly different on Travis-CI
371-
# depending on whether jruby + JRUBY_OPTS="--1.9" is used and or using
372-
# jruby-19mode with the later the LOADED_FEATURES do get expanded e.g. :
373-
#
374-
# "/home/travis/builds/kares/jruby-rack/target/classes/rack/handler/servlet.rb",
375-
# "/home/travis/builds/kares/jruby-rack/target/classes/jruby/rack.rb",
376-
# "/home/travis/builds/kares/jruby-rack/target/classes/jruby/rack/environment.rb",
377-
# "java.rb",
378-
# "/home/travis/.rvm/rubies/jruby-1.6.8-d19/lib/ruby/site_ruby/shared/builtin/javasupport.rb",
379-
# "/home/travis/.rvm/rubies/jruby-1.6.8-d19/lib/ruby/site_ruby/shared/builtin/javasupport/java.rb",
380-
# ...
381-
#
382-
# compared to jruby --1.9 :
383-
#
384-
# "enumerator.jar",
385-
# "rack/handler/servlet.rb",
386-
# "jruby/rack.rb",
387-
# "jruby/rack/environment.rb",
388-
# "java.rb",
389-
# "builtin/javasupport.rb",
390-
# "builtin/javasupport/java.rb",
391-
# ...
392-
393-
reject_files =
394-
"p =~ /.jar$/ || " +
395-
"p =~ /^builtin/ || " +
396-
"p =~ /java.rb$/ || p =~ /jruby.rb$/ || " +
397-
"p =~ /jruby\\/java.*.rb/ || " +
398-
"p =~ /jruby\\/rack.*.rb/ || " +
399-
"p =~ /^rack\\/handler\\/servlet/"
400-
# NOTE: fails with JRuby 1.7 as it has all kind of things loaded e.g. :
401-
# thread.rb, rbconfig.rb, java.rb, lib/ruby/shared/rubygems.rb etc
402-
should_eval_as_eql_to "$LOADED_FEATURES.reject { |p| #{reject_files} }", []
403-
end
404-
end
405-
406355
it "initializes the $servlet_context global variable" do
407356
@runtime = app_factory.new_runtime
408357
should_not_eval_as_nil "defined?($servlet_context)"
@@ -429,10 +378,10 @@ def newRuntime() # use the current runtime instead of creating new
429378
set_config 'jruby.runtime.env', 'false'
430379
set_config 'jruby.runtime.env.rubyopt', 'true'
431380

432-
app_factory = app_factory_with_RUBYOPT '-rubygems'
381+
app_factory = app_factory_with_RUBYOPT '-W:no-deprecated'
433382
@runtime = app_factory.newRuntime
434383
should_eval_as_nil "ENV['HOME']"
435-
should_eval_as_eql_to "ENV['RUBYOPT']", '-rubygems'
384+
should_eval_as_eql_to "ENV['RUBYOPT']", '-W:no-deprecated'
436385
end
437386

438387
it "keeps RUBYOPT by default with empty ENV (backwards compat)" do
@@ -490,7 +439,7 @@ def newRuntime() # use the current runtime instead of creating new
490439

491440
private
492441

493-
def app_factory_with_RUBYOPT(rubyopt = '-rubygems')
442+
def app_factory_with_RUBYOPT(rubyopt)
494443
app_factory =
495444
Class.new(org.jruby.rack.DefaultRackApplicationFactory) do
496445

@@ -613,7 +562,7 @@ def reset_config
613562
it "should init and create application object" do
614563
# NOTE: a workaround to be able to mock it :
615564
klass = Class.new(RailsRackApplicationFactory) do
616-
def createRackServletWrapper(runtime, rackup); end
565+
def createRackServletWrapper(runtime, rackup, filename); end
617566
end
618567
@app_factory = klass.new
619568

@@ -990,7 +939,6 @@ def createRackServletWrapper(runtime, rackup); end
990939
begin
991940
@shared_factory.init(@rack_context)
992941
rescue org.jruby.rack.RackInitializationException => e
993-
e = unwrap_native_exception(e)
994942
expect( e.message ).to eql 'java.lang.ArithmeticException: 42'
995943
else
996944
fail "expected to rescue RackInitializationException"

src/spec/ruby/spec_helper.rb

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,6 @@ def silence_warnings(&block)
5757
JRuby::Rack::Helpers.silence_warnings(&block)
5858
end
5959

60-
def unwrap_native_exception(e)
61-
# JRuby 1.6.8 issue :
62-
# begin
63-
# ...
64-
# rescue org.jruby.rack.RackInitializationException => e
65-
# # e is still wrapped in a NativeException !
66-
# e.cause.class.name == 'org.jruby.rack.RackInitializationException'
67-
# end
68-
if JRUBY_VERSION < '1.7.0'
69-
e.is_a?(NativeException) ? e.cause : e
70-
else
71-
e
72-
end
73-
end
74-
7560
@@servlet_30 = nil
7661

7762
def servlet_30?

0 commit comments

Comments
 (0)