Skip to content

Commit f487547

Browse files
committed
update Rails 4.0 stub (from stable release now) + handle some rspec warns
1 parent c0a2b5c commit f487547

File tree

26 files changed

+324
-69
lines changed

26 files changed

+324
-69
lines changed

src/spec/ruby/jruby/rack/integration_spec.rb

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
java_import org.jruby.rack.rails.RailsRackApplicationFactory
1515

1616
describe "integration" do
17-
17+
1818
#after(:all) { JRuby::Rack.context = nil }
19-
19+
2020
describe 'rack (lambda)' do
2121

2222
before do
@@ -96,11 +96,11 @@
9696
set_compat_version servlet_context
9797
servlet_context
9898
end
99-
99+
100100
it "initializes (pooling by default)" do
101101
listener = org.jruby.rack.rails.RailsServletContextListener.new
102102
listener.contextInitialized javax.servlet.ServletContextEvent.new(servlet_context)
103-
103+
104104
rack_factory = servlet_context.getAttribute("rack.factory")
105105
rack_factory.should be_a(RackApplicationFactory)
106106
rack_factory.should be_a(PoolingRackApplicationFactory)
@@ -128,12 +128,12 @@
128128
end
129129

130130
end
131-
131+
132132
describe 'rails 3.0', :lib => :rails30 do
133133

134134
before(:all) { copy_gemfile("rails30") }
135135

136-
let(:base_path) { "file://#{STUB_DIR}/rails30" }
136+
def base_path; "file://#{STUB_DIR}/rails30" end
137137

138138
it_should_behave_like 'a rails app'
139139

@@ -153,7 +153,7 @@
153153
@runtime = @rack_factory.getApplication.getRuntime
154154
expect_to_have_monkey_patched_chunked
155155
end
156-
156+
157157
end
158158

159159
context "initialized (custom)" do
@@ -178,7 +178,7 @@
178178

179179
before(:all) { copy_gemfile("rails31") }
180180

181-
let(:base_path) { "file://#{STUB_DIR}/rails31" }
181+
def base_path; "file://#{STUB_DIR}/rails31" end
182182

183183
it_should_behave_like 'a rails app'
184184

@@ -213,7 +213,7 @@
213213
@runtime = @rack_factory.getApplication.getRuntime
214214
expect_to_have_monkey_patched_chunked
215215
end
216-
216+
217217
end
218218

219219
end
@@ -222,7 +222,7 @@
222222

223223
before(:all) { copy_gemfile("rails32") }
224224

225-
let(:base_path) { "file://#{STUB_DIR}/rails32" }
225+
def base_path; "file://#{STUB_DIR}/rails32" end
226226

227227
it_should_behave_like 'a rails app'
228228

@@ -249,36 +249,36 @@
249249

250250
should_eval_as_eql_to "Rails.logger.level", Logger::INFO
251251
end
252-
252+
253253
it "sets up public_path (as for a war)" do
254254
@runtime = @rack_factory.getApplication.getRuntime
255255
should_eval_as_eql_to "Rails.public_path", "#{STUB_DIR}/rails32"
256256
# make sure it was set early on (before initializers run) :
257257
should_eval_as_not_nil "defined? Rails32::Application::PUBLIC_PATH"
258258
should_eval_as_eql_to "Rails32::Application::PUBLIC_PATH", "#{STUB_DIR}/rails32"
259259
# check if image_tag resolves path to images correctly :
260-
should_eval_as_eql_to %q{
260+
should_eval_as_eql_to %q{
261261
config = ActionController::Base.config;
262262
asset_paths = ActionView::Helpers::AssetTagHelper::AssetPaths.new(config);
263263
image_path = asset_paths.compute_public_path('image.jpg', 'images');
264264
image_path[0, 18]
265265
}, '/images/image.jpg?'
266266
end
267-
267+
268268
it "disables rack's chunked support (by default)" do
269269
@runtime = @rack_factory.getApplication.getRuntime
270270
expect_to_have_monkey_patched_chunked
271271
end
272-
272+
273273
end
274-
274+
275275
end
276276

277277
describe 'rails 4.0', :lib => :rails40 do
278278

279279
before(:all) { copy_gemfile("rails40") }
280280

281-
let(:base_path) { "file://#{STUB_DIR}/rails40" }
281+
def base_path; "file://#{STUB_DIR}/rails40" end
282282

283283
it_should_behave_like 'a rails app'
284284

@@ -300,26 +300,26 @@
300300
should_eval_as_not_nil "Rails.logger"
301301
# NOTE: TaggedLogging is a module that extends the instance now :
302302
should_eval_as_eql_to "Rails.logger.is_a? ActiveSupport::TaggedLogging", true
303-
should_eval_as_eql_to "Rails.logger.instance_variable_get(:'@logdev').dev.class.name",
303+
should_eval_as_eql_to "Rails.logger.instance_variable_get(:'@logdev').dev.class.name",
304304
'JRuby::Rack::ServletLog'
305305
should_eval_as_eql_to "Rails.logger.level", Logger::INFO
306306
end
307-
307+
308308
it "sets up public_path (as for a war)" do
309309
@runtime = @rack_factory.getApplication.getRuntime
310310
should_eval_as_eql_to "Rails.public_path.to_s", "#{STUB_DIR}/rails40"
311-
should_eval_as_eql_to %q{
312-
config = ActionController::Base.config;
313-
asset_paths = ActionView::Helpers::AssetTagHelper::AssetPaths.new(config);
314-
image_path = asset_paths.compute_public_path('image.jpg', 'images');
315-
image_path[0, 18]
316-
}, '/images/image.jpg?'
311+
should_eval_as_eql_to %q{
312+
class AssetPathTest; include ActionView::Helpers::AssetUrlHelper end;
313+
asset_helper = AssetPathTest.new;
314+
image_path = asset_helper.image_path('image.jpg');
315+
image_path[0, 17]
316+
}, '/images/image.jpg'
317317
end
318-
318+
319319
end
320-
320+
321321
end
322-
322+
323323
describe 'rails 2.3', :lib => :rails23 do
324324

325325
before(:all) do
@@ -343,31 +343,31 @@
343343
should_eval_as_not_nil "defined?(Rack.release)"
344344
should_eval_as_eql_to "Rack.release.to_s[0, 3]", '1.1'
345345
end
346-
346+
347347
it "booted with a servlet logger" do
348348
@runtime = @rack_factory.getApplication.getRuntime
349349
should_eval_as_not_nil "defined?(Rails)"
350350
should_eval_as_not_nil "defined?(Rails.logger)"
351-
351+
352352
should_eval_as_not_nil "defined?(ActiveSupport::BufferedLogger) && Rails.logger.is_a?(ActiveSupport::BufferedLogger)"
353353
should_eval_as_not_nil "Rails.logger.send(:instance_variable_get, '@log')"
354-
should_eval_as_eql_to "log = Rails.logger.send(:instance_variable_get, '@log');" +
354+
should_eval_as_eql_to "log = Rails.logger.send(:instance_variable_get, '@log');" +
355355
"log.class.name", 'JRuby::Rack::ServletLog'
356356
should_eval_as_eql_to "Rails.logger.level", Logger::INFO
357-
357+
358358
@runtime.evalScriptlet "Rails.logger.debug 'logging works'"
359359
end
360-
360+
361361
end
362362

363363
end
364-
364+
365365
def expect_to_have_monkey_patched_chunked
366366
@runtime.evalScriptlet "require 'rack/chunked'"
367367
script = %{
368368
headers = { 'Transfer-Encoding' => 'chunked' }
369369
370-
body = [ \"1\".freeze, \"\", \"\nsecond\" ]
370+
body = [ \"1\".freeze, \"\", \"\nsecond\" ]
371371
372372
if defined? Rack::Chunked::Body # Rails 3.x
373373
body = Rack::Chunked::Body.new body
@@ -382,7 +382,7 @@ def expect_to_have_monkey_patched_chunked
382382
}
383383
should_eval_as_eql_to script, "1\nsecond"
384384
end
385-
385+
386386
def initialize_rails(env = nil, servlet_context = @servlet_context)
387387
if ! servlet_context || servlet_context.is_a?(String)
388388
base = servlet_context.is_a?(String) ? servlet_context : nil
@@ -407,7 +407,7 @@ def new_servlet_context(base_path = nil)
407407
set_compat_version servlet_context
408408
servlet_context
409409
end
410-
410+
411411
def set_compat_version(servlet_context = @servlet_context)
412412
if JRuby.runtime.is1_9
413413
servlet_context.addInitParameter("jruby.compat.version", '1.9')

src/spec/ruby/spec_helper.rb

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
Maven.set_classpath
1818

1919
module SharedHelpers
20-
20+
2121
java_import 'org.jruby.rack.RackContext'
2222
java_import 'org.jruby.rack.RackConfig'
2323
java_import 'org.jruby.rack.servlet.ServletRackContext'
2424
java_import 'javax.servlet.ServletContext'
2525
java_import 'javax.servlet.ServletConfig'
26-
26+
2727
def mock_servlet_context
2828
@rack_config ||= RackConfig.impl {}
2929
@rack_context ||= ServletRackContext.impl {}
@@ -40,11 +40,11 @@ def mock_servlet_context
4040
@servlet_config.stub!(:getServletName).and_return "A Servlet"
4141
@servlet_config.stub!(:getServletContext).and_return @servlet_context
4242
end
43-
43+
4444
def silence_warnings(&block)
4545
JRuby::Rack::Helpers.silence_warnings(&block)
4646
end
47-
47+
4848
def unwrap_native_exception(e)
4949
# JRuby 1.6.8 issue :
5050
# begin
@@ -59,17 +59,17 @@ def unwrap_native_exception(e)
5959
e
6060
end
6161
end
62-
62+
6363
def set_rack_input(servlet_env)
6464
require 'jruby'
6565
input_class = org.jruby.rack.RackInput.getRackInputClass(JRuby.runtime)
6666
input = input_class.new(servlet_env.getInputStream)
6767
servlet_env.set_io input # servlet_env.instance_variable_set :@_io, input
6868
input
6969
end
70-
70+
7171
@@raise_logger = nil
72-
72+
7373
def raise_logger
7474
@@raise_logger ||= org.jruby.rack.RackLogger.impl do |name, *args|
7575
if name.to_s == 'log' && args[0] =~ /^(ERROR|WARN):/
@@ -81,7 +81,7 @@ def raise_logger
8181
end
8282
end
8383
end
84-
84+
8585
# org.jruby.Ruby.evalScriptlet helpers - comparing values from different runtimes
8686

8787
def should_eval_as_eql_to(code, expected, options = {})
@@ -91,36 +91,36 @@ def should_eval_as_eql_to(code, expected, options = {})
9191
runtime, options = options, {}
9292
end
9393
message = options[:message] || "expected eval #{code.inspect} to be == $expected but was $actual"
94-
be_flag = options.has_key?(:should) ? options[:should] : be_true
95-
94+
be_flag = options.has_key?(:should) ? options[:should] : be(true)
95+
9696
expected = expected.inspect.to_java
9797
actual = runtime.evalScriptlet(code).inspect.to_java
9898
actual.equals(expected).should be_flag, message.gsub('$expected', expected.to_s).gsub('$actual', actual.to_s)
9999
end
100-
100+
101101
def should_eval_as_not_eql_to(code, expected, options = {})
102-
should_eval_as_eql_to(code, expected, options.merge(:should => be_false,
102+
should_eval_as_eql_to(code, expected, options.merge(:should => be(false),
103103
:message => options[:message] || "expected eval #{code.inspect} to be != $expected but was not")
104104
)
105105
end
106-
106+
107107
def should_eval_as_nil(code, runtime = @runtime)
108-
should_eval_as_eql_to code, nil, :runtime => runtime,
108+
should_eval_as_eql_to code, nil, :runtime => runtime,
109109
:message => "expected eval #{code.inspect} to be nil but was $actual"
110110
end
111111

112112
def should_eval_as_not_nil(code, runtime = @runtime)
113-
should_eval_as_eql_to code, nil, :should => be_false, :runtime => runtime,
113+
should_eval_as_eql_to code, nil, :should => be(false), :runtime => runtime,
114114
:message => "expected eval #{code.inspect} to not be nil but was"
115115
end
116-
116+
117117
def should_not_eval_as_nil(code, runtime = @runtime) # alias
118118
should_eval_as_not_nil(code, runtime)
119119
end
120-
120+
121121
end
122122

123-
# NOTE: avoid chunked-patch (loaded by default from a hook at
123+
# NOTE: avoid chunked-patch (loaded by default from a hook at
124124
# DefaultRackApplicationFactory.initRuntime) to be loaded in (spec) runtime :
125125
$LOADED_FEATURES << 'jruby/rack/chunked.rb'
126126

@@ -140,13 +140,13 @@ def should_not_eval_as_nil(code, runtime = @runtime) # alias
140140
$LOAD_PATH.unshift File.expand_path('../rails/stub', __FILE__) unless defined?(Rails::VERSION)
141141

142142
# current 'library' environment (based on appraisals) e.g. :rails31
143-
CURRENT_LIB = defined?(Rails::VERSION) ?
143+
CURRENT_LIB = defined?(Rails::VERSION) ?
144144
:"rails#{Rails::VERSION::MAJOR}#{Rails::VERSION::MINOR}" : :stub
145145

146146
RSpec.configure do |config|
147147

148148
config.include SharedHelpers
149-
149+
150150
config.before :each do
151151
@env_save = ENV.to_hash
152152
mock_servlet_context
@@ -158,7 +158,7 @@ def should_not_eval_as_nil(code, runtime = @runtime) # alias
158158
Dir.chdir(WD_START) unless Dir.getwd == WD_START
159159
$servlet_context = nil if defined? $servlet_context
160160
end
161-
161+
162162
config.filter_run_excluding :lib => lambda { |lib|
163163
return false if lib.nil? # no :lib => specified run with all
164164
lib = lib.is_a?(Array) ? lib : [ lib ]
@@ -170,14 +170,14 @@ def should_not_eval_as_nil(code, runtime = @runtime) # alias
170170
end
171171
! lib.include?(CURRENT_LIB)
172172
}
173-
173+
174174
config.backtrace_clean_patterns = [
175175
/bin\//,
176176
#/gems/,
177177
/spec\/spec_helper\.rb/,
178178
/lib\/rspec\/(core|expectations|matchers|mocks)/
179179
]
180-
180+
181181
end
182182

183183
java_import org.jruby.rack.mock.MockServletConfig

0 commit comments

Comments
 (0)