Skip to content

Commit

Permalink
Correct application specs for later JRubies
Browse files Browse the repository at this point in the history
- 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]>
  • Loading branch information
chadlwilson committed Jun 28, 2024
1 parent 064b57c commit 34f390c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 70 deletions.
58 changes: 3 additions & 55 deletions src/spec/ruby/rack/application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -352,57 +352,6 @@ def newRuntime() # use the current runtime instead of creating new
should_eval_as_eql_to "Gem.loaded_specs['rack'].version.to_s", '1.3.6'
end

# should not matter on 1.7.x due https://github.com/jruby/jruby/pull/123
if JRUBY_VERSION < '1.7.0'
it "does not load any features (until load path is adjusted)" do
set_runtime_environment("false")
# due to incorrectly detected jruby.home some container e.g. WebSphere 8
# fail if things such as 'fileutils' get required during runtime init !

# TODO: WTF? JRuby magic - $LOADED_FEATURES seems to get "inherited" if
# Ruby.newInstance(config) is called with the factory's defaultConfig,
# but only if it's executed with bundler e.g. `bundle exec rake spec`
#@runtime = app_factory.new_runtime
@runtime = org.jruby.Ruby.newInstance
app_factory.send :initRuntime, @runtime

#@runtime.evalScriptlet 'puts "initRuntime $LOADED_FEATURES: #{$LOADED_FEATURES.inspect}"'
# NOTE: the above scriptlet behaves slightly different on Travis-CI
# depending on whether jruby + JRUBY_OPTS="--1.9" is used and or using
# jruby-19mode with the later the LOADED_FEATURES do get expanded e.g. :
#
# "/home/travis/builds/kares/jruby-rack/target/classes/rack/handler/servlet.rb",
# "/home/travis/builds/kares/jruby-rack/target/classes/jruby/rack.rb",
# "/home/travis/builds/kares/jruby-rack/target/classes/jruby/rack/environment.rb",
# "java.rb",
# "/home/travis/.rvm/rubies/jruby-1.6.8-d19/lib/ruby/site_ruby/shared/builtin/javasupport.rb",
# "/home/travis/.rvm/rubies/jruby-1.6.8-d19/lib/ruby/site_ruby/shared/builtin/javasupport/java.rb",
# ...
#
# compared to jruby --1.9 :
#
# "enumerator.jar",
# "rack/handler/servlet.rb",
# "jruby/rack.rb",
# "jruby/rack/environment.rb",
# "java.rb",
# "builtin/javasupport.rb",
# "builtin/javasupport/java.rb",
# ...

reject_files =
"p =~ /.jar$/ || " +
"p =~ /^builtin/ || " +
"p =~ /java.rb$/ || p =~ /jruby.rb$/ || " +
"p =~ /jruby\\/java.*.rb/ || " +
"p =~ /jruby\\/rack.*.rb/ || " +
"p =~ /^rack\\/handler\\/servlet/"
# NOTE: fails with JRuby 1.7 as it has all kind of things loaded e.g. :
# thread.rb, rbconfig.rb, java.rb, lib/ruby/shared/rubygems.rb etc
should_eval_as_eql_to "$LOADED_FEATURES.reject { |p| #{reject_files} }", []
end
end

it "initializes the $servlet_context global variable" do
@runtime = app_factory.new_runtime
should_not_eval_as_nil "defined?($servlet_context)"
Expand All @@ -429,10 +378,10 @@ def newRuntime() # use the current runtime instead of creating new
set_config 'jruby.runtime.env', 'false'
set_config 'jruby.runtime.env.rubyopt', 'true'

app_factory = app_factory_with_RUBYOPT '-rubygems'
app_factory = app_factory_with_RUBYOPT '-W:no-deprecated'
@runtime = app_factory.newRuntime
should_eval_as_nil "ENV['HOME']"
should_eval_as_eql_to "ENV['RUBYOPT']", '-rubygems'
should_eval_as_eql_to "ENV['RUBYOPT']", '-W:no-deprecated'
end

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

private

def app_factory_with_RUBYOPT(rubyopt = '-rubygems')
def app_factory_with_RUBYOPT(rubyopt)
app_factory =
Class.new(org.jruby.rack.DefaultRackApplicationFactory) do

Expand Down Expand Up @@ -990,7 +939,6 @@ def createRackServletWrapper(runtime, rackup); end
begin
@shared_factory.init(@rack_context)
rescue org.jruby.rack.RackInitializationException => e
e = unwrap_native_exception(e)
expect( e.message ).to eql 'java.lang.ArithmeticException: 42'
else
fail "expected to rescue RackInitializationException"
Expand Down
15 changes: 0 additions & 15 deletions src/spec/ruby/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,6 @@ def silence_warnings(&block)
JRuby::Rack::Helpers.silence_warnings(&block)
end

def unwrap_native_exception(e)
# JRuby 1.6.8 issue :
# begin
# ...
# rescue org.jruby.rack.RackInitializationException => e
# # e is still wrapped in a NativeException !
# e.cause.class.name == 'org.jruby.rack.RackInitializationException'
# end
if JRUBY_VERSION < '1.7.0'
e.is_a?(NativeException) ? e.cause : e
else
e
end
end

@@servlet_30 = nil

def servlet_30?
Expand Down

0 comments on commit 34f390c

Please sign in to comment.