Skip to content

Commit b2187b9

Browse files
committed
minor improvements from running spec on 1.7.0 preview1
1 parent a6876e0 commit b2187b9

File tree

3 files changed

+37
-36
lines changed

3 files changed

+37
-36
lines changed

src/main/java/org/jruby/rack/DefaultRackApplicationFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ private RubyInstanceConfig createRuntimeConfig() {
181181
return config;
182182
}
183183

184-
private void initializeRuntime(Ruby runtime) throws RackInitializationException {
184+
// NOTE: only visible due #jruby/rack/application_spec.rb on JRuby 1.7.x
185+
void initializeRuntime(Ruby runtime) throws RackInitializationException {
185186
try {
186187
IRubyObject context = JavaUtil.convertJavaToRuby(runtime, rackContext);
187188
runtime.getGlobalVariables().set("$servlet_context", context);

src/spec/ruby/rack/application_spec.rb

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
require File.expand_path('spec_helper', File.dirname(__FILE__) + '/..')
99
require 'jruby/rack/environment'
1010

11-
import org.jruby.rack.DefaultRackApplication
12-
13-
describe DefaultRackApplication, "call" do
11+
describe org.jruby.rack.DefaultRackApplication, "call" do
1412

1513
before :each do
1614
@rack_env = mock("rack_request_env")
@@ -27,7 +25,7 @@
2725
@rack_response
2826
end
2927

30-
application = DefaultRackApplication.new
28+
application = org.jruby.rack.DefaultRackApplication.new
3129
application.setApplication(ruby_object)
3230
application.call(@rack_env).should == @rack_response
3331
end
@@ -97,16 +95,16 @@ def it_should_rewind_body
9795
org.jruby.rack.RackResponse.impl {}
9896
end
9997

100-
application = DefaultRackApplication.new
98+
application = org.jruby.rack.DefaultRackApplication.new
10199
application.setApplication(ruby_object)
102100
application.call(@rack_env)
103101
end
104102

105103
end
106104

107-
import org.jruby.rack.DefaultRackApplicationFactory
108-
109-
describe DefaultRackApplicationFactory do
105+
describe org.jruby.rack.DefaultRackApplicationFactory do
106+
107+
java_import org.jruby.rack.DefaultRackApplicationFactory
110108

111109
before :each do
112110
@app_factory = DefaultRackApplicationFactory.new
@@ -238,9 +236,16 @@ def createRackServletWrapper(runtime, rackup); end
238236
# but only if it's executed with bundler e.g. `bundle exec rake spec`
239237
#@runtime = app_factory.new_runtime
240238
@runtime = org.jruby.Ruby.newInstance
241-
app_factory.initializeRuntime(@runtime)
242-
243-
reject_files = "p =~ /jar$/ || p =~ /^builtin/ || p =~ /^jruby/ || p =~ /^java/ || p == 'rack/handler/servlet.rb'"
239+
app_factory.send :initializeRuntime, @runtime
240+
241+
reject_files =
242+
"p =~ /.jar$/ || " +
243+
"p =~ /^builtin/ || " +
244+
"p =~ /jruby\\/java.*.rb/ || " +
245+
"p =~ /jruby\\/rack.*.rb/ || " +
246+
"p == /rack\\/handler\\/servlet.rb/"
247+
# TODO: fails with JRuby 1.7 as it has all kind of things loaded e.g. :
248+
# thread.rb, rbconfig.rb, java.rb, lib/ruby/shared/rubygems.rb etc
244249
should_eval_as_eql_to "$LOADED_FEATURES.reject { |p| #{reject_files} }", []
245250
end
246251

@@ -342,9 +347,9 @@ def createRackServletWrapper(runtime, rackup); end
342347
end
343348
end
344349

345-
import org.jruby.rack.rails.RailsRackApplicationFactory
346-
347-
describe RailsRackApplicationFactory do
350+
describe org.jruby.rack.rails.RailsRackApplicationFactory do
351+
352+
java_import org.jruby.rack.rails.RailsRackApplicationFactory
348353

349354
before :each do
350355
@app_factory = RailsRackApplicationFactory.new
@@ -381,12 +386,10 @@ def createRackServletWrapper(runtime, rackup); end
381386

382387
end
383388

384-
import org.jruby.rack.PoolingRackApplicationFactory
385-
386-
describe PoolingRackApplicationFactory do
389+
describe org.jruby.rack.PoolingRackApplicationFactory do
387390
before :each do
388391
@factory = mock "factory"
389-
@pool = PoolingRackApplicationFactory.new @factory
392+
@pool = org.jruby.rack.PoolingRackApplicationFactory.new @factory
390393
end
391394

392395
it "should initialize the delegate factory when initialized" do
@@ -478,12 +481,10 @@ def createRackServletWrapper(runtime, rackup); end
478481
end
479482
end
480483

481-
import org.jruby.rack.SharedRackApplicationFactory
482-
483-
describe SharedRackApplicationFactory do
484+
describe org.jruby.rack.SharedRackApplicationFactory do
484485
before :each do
485486
@factory = mock "factory"
486-
@shared = SharedRackApplicationFactory.new @factory
487+
@shared =org.jruby.rack.SharedRackApplicationFactory.new @factory
487488
end
488489

489490
it "should initialize the delegate factory and create the shared application when initialized" do
@@ -506,8 +507,11 @@ def createRackServletWrapper(runtime, rackup); end
506507
@factory.should_receive(:init).with(@rack_context)
507508
app = mock "application"
508509
@factory.should_receive(:getApplication).and_raise org.jruby.rack.RackInitializationException.new(nil)
509-
@shared.init(@rack_context) rescue nil
510-
@shared.getApplication.should_not be_nil
510+
begin
511+
@shared.init(@rack_context)
512+
rescue org.jruby.rack.RackInitializationException
513+
end
514+
@shared.getApplication.should_not be nil
511515
end
512516

513517
it "should return the same application for any newApplication or getApplication call" do

src/spec/ruby/rack/tag_spec.rb

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,14 @@
77

88
require File.expand_path('spec_helper', File.dirname(__FILE__) + '/..')
99

10-
import org.jruby.rack.RackTag
11-
import org.jruby.rack.fake.FakePageContext
12-
import org.jruby.rack.fake.FakeJspWriter
13-
1410
class ExceptionThrower
1511
def call(request)
1612
raise 'Had a problem!'
1713
end
1814
end
1915

20-
describe RackTag do
21-
16+
describe org.jruby.rack.RackTag do
17+
2218
before :each do
2319
@result = mock("Rack Result")
2420
@result.stub!(:getBody).and_return("Hello World!")
@@ -36,17 +32,17 @@ def call(request)
3632
@servlet_request.stub!(:getContextPath).and_return ""
3733
@servlet_response = mock("Servlet Response")
3834

39-
@writable = FakeJspWriter.new
40-
@page_context = FakePageContext.new(@servlet_context, @servlet_request, @servlet_response, @writable)
35+
@writable = org.jruby.rack.fake.FakeJspWriter.new
36+
@page_context = org.jruby.rack.fake.FakePageContext.new(@servlet_context, @servlet_request, @servlet_response, @writable)
4137

42-
@tag = RackTag.new
38+
@tag = org.jruby.rack.RackTag.new
4339
@tag.setPageContext(@page_context)
4440
@tag.setPath("/controller/action/id")
4541
@tag.setParams("fruit=apple&horse_before=cart")
4642
end
4743

4844
it 'should be able to construct a new tag' do
49-
RackTag.new
45+
org.jruby.rack.RackTag.new
5046
end
5147

5248
it 'should get an application and return it to the pool' do
@@ -62,7 +58,7 @@ def call(request)
6258

6359
begin
6460
@tag.doEndTag
65-
rescue
61+
rescue Java::JavaxServletJsp::JspException
6662
#noop
6763
end
6864
end

0 commit comments

Comments
 (0)