something went wrong<\/p>\n\s{2}<\/div>/m
end
it "does not render detail info when 'rack.showstatus.detail' set to false" do
- @env[ 'HTTP_ACCEPT' ] = '*/*'; init_exception
- @env[ 'rack.showstatus.detail' ] = false
+ @env['HTTP_ACCEPT'] = '*/*'; init_exception
+ @env['rack.showstatus.detail'] = false
response = show_status.call(@env)
- expect( response[0] ).to eql 500
- expect( response[2][0] ).to match /
\s*?<\/div>/m
- expect( @env[ 'rack.showstatus.detail' ] ).to be false
+ expect(response[0]).to eql 500
+ expect(response[2][0]).to match /
\s*?<\/div>/m
+ expect(@env['rack.showstatus.detail']).to be false
end
it "with response < 400 and 'rack.showstatus.detail' set to false does not render exception" do
- @env[ 'HTTP_ACCEPT' ] = '*/*'; init_exception
- @env[ 'rack.showstatus.detail' ] = false
+ @env['HTTP_ACCEPT'] = '*/*'; init_exception
+ @env['rack.showstatus.detail'] = false
- def error_app.map_error_code(exc); 399 end
+ def error_app.map_error_code(exc)
+ ; 399
+ end
response = show_status.call(@env)
- expect( response[0] ).to eql 399
+ expect(response[0]).to eql 399
# 399, {"Content-Type"=>"text/plain", "X-Cascade"=>"pass"}, []
- expect( @env[ 'rack.showstatus.detail' ] ).to be false
+ expect(@env['rack.showstatus.detail']).to be false
end
end
@@ -149,7 +153,7 @@ def error_app.map_error_code(exc); 399 end
def init_exception(cause = nil)
exception = org.jruby.rack.RackInitializationException.new("something went wrong", cause)
- @env[ org.jruby.rack.RackEnvironment::EXCEPTION ] = exception
+ @env[org.jruby.rack.RackEnvironment::EXCEPTION] = exception
end
require 'fileutils'; require 'tmpdir'
@@ -171,7 +175,7 @@ def in_tmpdir_with_files(files = {})
before(:all) { require 'jruby/rack/errors' }
it "still works (backward compat)" do
- expect( JRuby::Rack::Errors ).to be JRuby::Rack::ErrorApp
+ expect(JRuby::Rack::Errors).to be JRuby::Rack::ErrorApp
end
end
diff --git a/src/spec/ruby/jruby/rack/helpers_spec.rb b/src/spec/ruby/jruby/rack/helpers_spec.rb
index 1332e2855..fa93b57b2 100644
--- a/src/spec/ruby/jruby/rack/helpers_spec.rb
+++ b/src/spec/ruby/jruby/rack/helpers_spec.rb
@@ -8,95 +8,96 @@
describe JRuby::Rack::Helpers do
include JRuby::Rack::Helpers
-
+
module A
ENV = Object.new
Some = :Some
module B
ENV = Object.new
+
class SomeKlass < Object
TRUE = 'TRUE'.freeze
end
end
end
-
+
it "constantizes from Object" do
- expect( constantize('ARGV') ).to be ARGV
- expect( constantize(:'Math::PI') ).to be ::Math::PI
+ expect(constantize('ARGV')).to be ARGV
+ expect(constantize(:'Math::PI')).to be ::Math::PI
end
it "constantizes using given context" do
- expect( constantize('ENV', A) ).to be A::ENV
- expect( constantize('ENV', A::B) ).to be A::B::ENV
+ expect(constantize('ENV', A)).to be A::ENV
+ expect(constantize('ENV', A::B)).to be A::B::ENV
end
-
+
it "constantizes using Object as context" do
- expect( constantize('ENV', Object) ).to be ::ENV
- expect( constantize('::ENV', A::B) ).to be ::ENV
+ expect(constantize('ENV', Object)).to be ::ENV
+ expect(constantize('::ENV', A::B)).to be ::ENV
end
it "constantizes (deeply) nested" do
- expect( constantize('A::B::SomeKlass') ).to be A::B::SomeKlass
+ expect(constantize('A::B::SomeKlass')).to be A::B::SomeKlass
end
it "constantizes nested with context" do
- expect( constantize('SomeKlass', A::B) ).to be A::B::SomeKlass
- expect( constantize('SomeKlass::TRUE', A::B) ).to be A::B::SomeKlass::TRUE
+ expect(constantize('SomeKlass', A::B)).to be A::B::SomeKlass
+ expect(constantize('SomeKlass::TRUE', A::B)).to be A::B::SomeKlass::TRUE
end
-
+
it "constantizes strictly" do
expect { constantize('Some', A::B) }.to raise_error(NameError)
end
it "constantizes non-stricly from Object (parent) context" do
- expect( constantize('ARGV', A) ).to be ::ARGV
- expect( constantize('ARGV', A::B) ).to be ::ARGV
+ expect(constantize('ARGV', A)).to be ::ARGV
+ expect(constantize('ARGV', A::B)).to be ::ARGV
end
-
+
it "strips name on constantize" do
- expect( constantize(' Math::PI ') ).to be Math::PI
- expect( constantize(:'ARGV ') ).to be ARGV
+ expect(constantize(' Math::PI ')).to be Math::PI
+ expect(constantize(:'ARGV ')).to be ARGV
end
-
+
it "underscores" do
- expect( underscore("ServletLog") ).to eql 'servlet_log'
- expect( underscore("Rack::Handler::Servlet") ).to eql 'rack/handler/servlet'
- expect( underscore("Rack::Handler::Servlet::DefaultEnv") ).to eql 'rack/handler/servlet/default_env'
+ expect(underscore("ServletLog")).to eql 'servlet_log'
+ expect(underscore("Rack::Handler::Servlet")).to eql 'rack/handler/servlet'
+ expect(underscore("Rack::Handler::Servlet::DefaultEnv")).to eql 'rack/handler/servlet/default_env'
end
-
+
it "underscores (with built-in JRuby conversion by default) on successive capital cases" do
- expect( underscore(:"JRuby") ).to eql 'jruby'
- expect( underscore("JRuby::Rack::ServletLog") ).to eql 'jruby/rack/servlet_log'
- expect( underscore("Math::PI") ).to eql 'math/pi'
- expect( underscore("Math::PIANO") ).to eql 'math/piano'
- expect( underscore("Net::HTTP::SSLError") ).to eql 'net/http/ssl_error'
- expect( underscore("MOD::LONGCamelizedNameFORAll") ).to eql 'mod/long_camelized_name_for_all'
+ expect(underscore(:"JRuby")).to eql 'jruby'
+ expect(underscore("JRuby::Rack::ServletLog")).to eql 'jruby/rack/servlet_log'
+ expect(underscore("Math::PI")).to eql 'math/pi'
+ expect(underscore("Math::PIANO")).to eql 'math/piano'
+ expect(underscore("Net::HTTP::SSLError")).to eql 'net/http/ssl_error'
+ expect(underscore("MOD::LONGCamelizedNameFORAll")).to eql 'mod/long_camelized_name_for_all'
end
it "underscores (with built-in JRuby conversion by default) JRuby like" do
- expect( underscore("JRubyRack") ).to eql 'jruby_rack'
- expect( underscore("RackJRuby") ).to eql 'rack_j_ruby' # only if it starts
- expect( underscore("Nested::JRubyRack") ).to eql 'nested/jruby_rack'
- expect( underscore("Nested::RackJRuby") ).to eql 'nested/rack_j_ruby' # only if it starts
+ expect(underscore("JRubyRack")).to eql 'jruby_rack'
+ expect(underscore("RackJRuby")).to eql 'rack_j_ruby' # only if it starts
+ expect(underscore("Nested::JRubyRack")).to eql 'nested/jruby_rack'
+ expect(underscore("Nested::RackJRuby")).to eql 'nested/rack_j_ruby' # only if it starts
end
-
+
it "underscores without conversions" do
- expect( underscore("JRuby", false) ).to eql 'j_ruby'
- expect( underscore("JRuby::Rack::Response", nil) ).to eql 'j_ruby/rack/response'
- expect( underscore("Math::PI", {}) ).to eql 'math/pi'
- expect( underscore("Math::PIANO", nil) ).to eql 'math/piano'
- expect( underscore("Net::HTTP::SSLError", false) ).to eql 'net/http/ssl_error'
- expect( underscore("MOD::LONGCamelizedNameFORAll", false) ).to eql 'mod/long_camelized_name_for_all'
+ expect(underscore("JRuby", false)).to eql 'j_ruby'
+ expect(underscore("JRuby::Rack::Response", nil)).to eql 'j_ruby/rack/response'
+ expect(underscore("Math::PI", {})).to eql 'math/pi'
+ expect(underscore("Math::PIANO", nil)).to eql 'math/piano'
+ expect(underscore("Net::HTTP::SSLError", false)).to eql 'net/http/ssl_error'
+ expect(underscore("MOD::LONGCamelizedNameFORAll", false)).to eql 'mod/long_camelized_name_for_all'
end
it "strips name on underscore" do
- expect( underscore(:" ServletLog ") ).to eql 'servlet_log'
- expect( underscore(" Rack::Handler::Servlet") ).to eql 'rack/handler/servlet'
+ expect(underscore(:" ServletLog ")).to eql 'servlet_log'
+ expect(underscore(" Rack::Handler::Servlet")).to eql 'rack/handler/servlet'
end
-
+
it "resolves a constant" do
- expect( resolve_constant("JRuby::Rack::Helpers::Some") ).to be_a Class
+ expect(resolve_constant("JRuby::Rack::Helpers::Some")).to be_a Class
expect { resolve_constant("JRuby::Rack::Helpers::Missing") }.to raise_error NameError
expect { resolve_constant("JRuby::Rack::Helpers::Another") }.to raise_error NameError
end
-
+
end
\ No newline at end of file
diff --git a/src/spec/ruby/jruby/rack/integration_spec.rb b/src/spec/ruby/jruby/rack/integration_spec.rb
index eb686262a..482271f68 100644
--- a/src/spec/ruby/jruby/rack/integration_spec.rb
+++ b/src/spec/ruby/jruby/rack/integration_spec.rb
@@ -1,4 +1,3 @@
-
require File.expand_path('spec_helper', File.dirname(__FILE__) + '/../..')
java_import org.jruby.rack.RackContext
@@ -24,26 +23,26 @@
it "initializes" do
@servlet_context.addInitParameter('rackup',
- "run lambda { |env| [ 200, {'Content-Type' => 'text/plain'}, 'OK' ] }"
+ "run lambda { |env| [ 200, {'Content-Type' => 'text/plain'}, 'OK' ] }"
)
listener = org.jruby.rack.RackServletContextListener.new
listener.contextInitialized javax.servlet.ServletContextEvent.new(@servlet_context)
rack_factory = @servlet_context.getAttribute("rack.factory")
- rack_factory.should be_a(RackApplicationFactory)
- rack_factory.should be_a(SharedRackApplicationFactory)
- rack_factory.realFactory.should be_a(DefaultRackApplicationFactory)
+ expect(rack_factory).to be_a(RackApplicationFactory)
+ expect(rack_factory).to be_a(SharedRackApplicationFactory)
+ expect(rack_factory.realFactory).to be_a(DefaultRackApplicationFactory)
- @servlet_context.getAttribute("rack.context").should be_a(RackContext)
- @servlet_context.getAttribute("rack.context").should be_a(ServletRackContext)
+ expect(@servlet_context.getAttribute("rack.context")).to be_a(RackContext)
+ expect(@servlet_context.getAttribute("rack.context")).to be_a(ServletRackContext)
end
context "initialized" do
before :each do
@servlet_context.addInitParameter('rackup',
- "run lambda { |env| [ 200, {'Via' => 'JRuby-Rack', 'Content-Type' => 'text/plain'}, 'OK' ] }"
+ "run lambda { |env| [ 200, {'Via' => 'JRuby-Rack', 'Content-Type' => 'text/plain'}, 'OK' ] }"
)
listener = org.jruby.rack.RackServletContextListener.new
listener.contextInitialized javax.servlet.ServletContextEvent.new(@servlet_context)
@@ -56,8 +55,8 @@
servlet = org.jruby.rack.RackServlet.new
servlet.init(servlet_config)
- expect( servlet.getContext ).to_not be nil
- expect( servlet.getDispatcher ).to_not be nil
+ expect(servlet.getContext).to_not be nil
+ expect(servlet.getDispatcher).to_not be nil
end
it "serves (servlet)" do
@@ -73,10 +72,10 @@
servlet.service(request, response)
- expect( response.getStatus ).to eql 200
- expect( response.getContentType ).to eql 'text/plain'
- expect( response.getContentAsString ).to eql 'OK'
- expect( response.getHeader("Via") ).to eql 'JRuby-Rack'
+ expect(response.getStatus).to eql 200
+ expect(response.getContentType).to eql 'text/plain'
+ expect(response.getContentAsString).to eql 'OK'
+ expect(response.getHeader("Via")).to eql 'JRuby-Rack'
end
end
@@ -97,14 +96,14 @@
listener.contextInitialized javax.servlet.ServletContextEvent.new(servlet_context)
rack_factory = servlet_context.getAttribute("rack.factory")
- rack_factory.should be_a(RackApplicationFactory)
- rack_factory.should be_a(PoolingRackApplicationFactory)
- rack_factory.realFactory.should be_a(RailsRackApplicationFactory)
+ expect(rack_factory).to be_a(RackApplicationFactory)
+ expect(rack_factory).to be_a(PoolingRackApplicationFactory)
+ expect(rack_factory.realFactory).to be_a(RailsRackApplicationFactory)
- servlet_context.getAttribute("rack.context").should be_a(RackContext)
- servlet_context.getAttribute("rack.context").should be_a(ServletRackContext)
+ expect(servlet_context.getAttribute("rack.context")).to be_a(RackContext)
+ expect(servlet_context.getAttribute("rack.context")).to be_a(ServletRackContext)
- rack_factory.getApplication.should be_a(DefaultRackApplication)
+ expect(rack_factory.getApplication).to be_a(DefaultRackApplication)
end
it "initializes shared (thread-safe) by default" do
@@ -112,11 +111,11 @@
listener.contextInitialized javax.servlet.ServletContextEvent.new(servlet_context)
rack_factory = servlet_context.getAttribute("rack.factory")
- rack_factory.should be_a(RackApplicationFactory)
- rack_factory.should be_a(SharedRackApplicationFactory)
- rack_factory.realFactory.should be_a(RailsRackApplicationFactory)
+ expect(rack_factory).to be_a(RackApplicationFactory)
+ expect(rack_factory).to be_a(SharedRackApplicationFactory)
+ expect(rack_factory.realFactory).to be_a(RailsRackApplicationFactory)
- rack_factory.getApplication.should be_a(DefaultRackApplication)
+ expect(rack_factory.getApplication).to be_a(DefaultRackApplication)
end
it "initializes shared (thread-safe) whem max runtimes is 1" do
@@ -126,22 +125,25 @@
listener.contextInitialized javax.servlet.ServletContextEvent.new(servlet_context)
rack_factory = servlet_context.getAttribute("rack.factory")
- rack_factory.should be_a(RackApplicationFactory)
- rack_factory.should be_a(SharedRackApplicationFactory)
- rack_factory.realFactory.should be_a(RailsRackApplicationFactory)
+ expect(rack_factory).to be_a(RackApplicationFactory)
+ expect(rack_factory).to be_a(SharedRackApplicationFactory)
+ expect(rack_factory.realFactory).to be_a(RailsRackApplicationFactory)
end
end
describe 'rails 7.2', lib: :rails72 do
- before(:all) do name = :rails72 # copy_gemfile :
+ before(:all) do
+ name = :rails72 # copy_gemfile :
FileUtils.cp File.join(GEMFILES_DIR, "#{name}.gemfile"), File.join(STUB_DIR, "#{name}/Gemfile")
FileUtils.cp File.join(GEMFILES_DIR, "#{name}.gemfile.lock"), File.join(STUB_DIR, "#{name}/Gemfile.lock")
Dir.chdir File.join(STUB_DIR, name.to_s)
end
- def base_path; "#{STUB_DIR}/rails72" end
+ def base_path
+ "#{STUB_DIR}/rails72"
+ end
it_should_behave_like 'a rails app'
@@ -152,7 +154,7 @@ def base_path; "#{STUB_DIR}/rails72" end
prepare_servlet_context(servlet_context)
end
end
- after(:all) { restore_rails }
+ after(:all) { restore_rails }
it "loaded rack ~> 2.2" do
@runtime = @rack_factory.getApplication.getRuntime
@@ -205,7 +207,7 @@ def expect_to_have_monkey_patched_chunked
end
def initialize_rails(env = nil, servlet_context = @servlet_context)
- if ! servlet_context || servlet_context.is_a?(String)
+ if !servlet_context || servlet_context.is_a?(String)
base = servlet_context.is_a?(String) ? servlet_context : nil
servlet_context = new_servlet_context(base)
end
@@ -236,7 +238,8 @@ def prepare_servlet_context(servlet_context)
GEMFILES_DIR = File.expand_path('../../../gemfiles', STUB_DIR)
- def copy_gemfile(name) # e.g. 'rails30'
+ def copy_gemfile(name)
+ # e.g. 'rails30'
FileUtils.cp File.join(GEMFILES_DIR, "#{name}.gemfile"), File.join(STUB_DIR, "#{name}/WEB-INF/Gemfile")
FileUtils.cp File.join(GEMFILES_DIR, "#{name}.gemfile.lock"), File.join(STUB_DIR, "#{name}/WEB-INF/Gemfile.lock")
end
diff --git a/src/spec/ruby/jruby/rack/logger_spec.rb b/src/spec/ruby/jruby/rack/logger_spec.rb
index 73e0cc477..deac5bf5d 100644
--- a/src/spec/ruby/jruby/rack/logger_spec.rb
+++ b/src/spec/ruby/jruby/rack/logger_spec.rb
@@ -30,71 +30,71 @@
it 'works with a servlet context' do
logger.debug?
logger.debug 'hogy basza meg a zold tucsok!'
- expect( real_logger.logged_content ).to match /^DEBUG.*hogy .* a zold tucsok!$/
+ expect(real_logger.logged_content).to match /^DEBUG.*hogy .* a zold tucsok!$/
end
it 'delegates to passed logger instance' do
logger.debug 'debugging'
- expect( real_logger.logged_content ).to match /^DEBUG.*debugging$/
+ expect(real_logger.logged_content).to match /^DEBUG.*debugging$/
real_logger.reset
logger.info 'infooo'
- expect( real_logger.logged_content ).to match /^INFO.*infooo$/
+ expect(real_logger.logged_content).to match /^INFO.*infooo$/
real_logger.reset
logger.warn 'warning'
- expect( real_logger.logged_content ).to match /^WARN.*warning$/
+ expect(real_logger.logged_content).to match /^WARN.*warning$/
real_logger.reset
logger.error 'errored'
- expect( real_logger.logged_content ).to match /^ERROR.*errored$/
+ expect(real_logger.logged_content).to match /^ERROR.*errored$/
real_logger.reset
logger.fatal 'totaal!'
- expect( real_logger.logged_content ).to match /^FATAL.*totaal!$/
+ expect(real_logger.logged_content).to match /^FATAL.*totaal!$/
end
it 'uses JRuby::Rack.context when no initialize argument' do
logger = JRuby::Rack::Logger.new
logger.debug?
logger.debug 'hogy basza meg a zold tucsok!'
- expect( logger.to_java(org.jruby.rack.RackLogger) ).to be rack_context
+ expect(logger.to_java(org.jruby.rack.RackLogger)).to be rack_context
end
it 'delegates level check (when level is not set)' do
real_logger.level = level::INFO
- expect( logger.debug? ).to be false
- expect( logger.info? ).to be true
+ expect(logger.debug?).to be false
+ expect(logger.info?).to be true
real_logger.level = level::WARN
- expect( logger.info? ).to be false
+ expect(logger.info?).to be false
end
it 'uses level check when level is explicitly set' do
real_logger.level = level::INFO
logger.level = 2 # Logger.::WARN
- expect( logger.info? ).to be false
- expect( logger.warn? ).to be true
+ expect(logger.info?).to be false
+ expect(logger.warn?).to be true
logger.level = nil
- expect( logger.info? ).to be true
+ expect(logger.info?).to be true
end
it "combines level check with delegate's level" do
real_logger.level = level::WARN
logger.level = 1 # Logger.::INFO
- expect( logger.debug? ).to be false
- expect( logger.info? ).to be false
- expect( logger.warn? ).to be true
+ expect(logger.debug?).to be false
+ expect(logger.info?).to be false
+ expect(logger.warn?).to be true
logger.level = nil
- expect( logger.info? ).to be false
- expect( logger.debug? ).to be false
- expect( logger.warn? ).to be true
+ expect(logger.info?).to be false
+ expect(logger.debug?).to be false
+ expect(logger.warn?).to be true
end
it "disables real logger's formatting when formatter is set" do
real_logger.formatting = true
- expect( real_logger.formatting? ).to be true
+ expect(real_logger.formatting?).to be true
logger.formatter = Proc.new { |severity, timestamp, progname, msg| "#{severity[0, 1]} #{msg}" }
logger.warn 'hogy basza meg a zold tucsok!'
- expect( real_logger.logged_content ).to eql "W hogy basza meg a zold tucsok!\n"
+ expect(real_logger.logged_content).to eql "W hogy basza meg a zold tucsok!\n"
- expect( real_logger.formatting? ).to be false
+ expect(real_logger.formatting?).to be false
end
it 'logs exception with trace when passed as argument' do
@@ -103,12 +103,12 @@
rescue => e
logger.debug(e)
end
- expect( real_logger.logged_content ).to match /^DEBUG.*?IndexError.*?TEST.*?at.*?logger_spec.rb.*/m
+ expect(real_logger.logged_content).to match /^DEBUG.*?IndexError.*?TEST.*?at.*?logger_spec.rb.*/m
end
it 'handles constant resolution (for Rails compatibility)' do
- expect( logger.class::DEBUG ).to eql 0
- expect( logger.class::FATAL ).to eql 4
+ expect(logger.class::DEBUG).to eql 0
+ expect(logger.class::FATAL).to eql 4
end
describe JRuby::Rack::ServletLog do
diff --git a/src/spec/ruby/jruby/rack/rack_ext_spec.rb b/src/spec/ruby/jruby/rack/rack_ext_spec.rb
index 089f681d5..0e074d5a1 100644
--- a/src/spec/ruby/jruby/rack/rack_ext_spec.rb
+++ b/src/spec/ruby/jruby/rack/rack_ext_spec.rb
@@ -19,23 +19,22 @@
end
it "should forward to servlet request dispatcher" do
- @servlet_request.should_receive(:getRequestDispatcher).
+ expect(@servlet_request).to receive(:getRequestDispatcher).
with('/foo').and_return dispatcher = double('dispatcher')
- dispatcher.should_receive(:forward).
+ expect(dispatcher).to receive(:forward).
with(@servlet_request, @servlet_response)
- @rack_request.should respond_to(:forward_to)
+ expect(@rack_request).to respond_to(:forward_to)
@rack_request.forward_to('/foo')
end
it "should include servlet response on render" do
- @servlet_request.should_receive(:getRequestDispatcher).
+ expect(@servlet_request).to receive(:getRequestDispatcher).
with('/foo').and_return dispatcher = double('dispatcher')
- org.jruby.rack.servlet.ServletRackIncludedResponse.
- should_receive(:new).with(@servlet_response).
- and_return included_response = double('included_response')
- included_response.should_receive(:getOutput).and_return 'foo output'
- dispatcher.should_receive(:include).with(@servlet_request, included_response)
- @rack_request.should respond_to(:render)
- @rack_request.render('/foo').should == 'foo output'
+ expect(org.jruby.rack.servlet.ServletRackIncludedResponse).to receive(:new).
+ with(@servlet_response).and_return included_response = double('included_response')
+ expect(included_response).to receive(:getOutput).and_return 'foo output'
+ expect(dispatcher).to receive(:include).with(@servlet_request, included_response)
+ expect(@rack_request).to respond_to(:render)
+ expect(@rack_request.render('/foo')).to eq 'foo output'
end
end
diff --git a/src/spec/ruby/jruby/rack/rails_booter_spec.rb b/src/spec/ruby/jruby/rack/rails_booter_spec.rb
index 30f39e3f4..64863f341 100644
--- a/src/spec/ruby/jruby/rack/rails_booter_spec.rb
+++ b/src/spec/ruby/jruby/rack/rails_booter_spec.rb
@@ -23,10 +23,10 @@
after { JRuby::Rack.context = nil; JRuby::Rack.logger = nil }
it "should determine RAILS_ROOT from the 'rails.root' init parameter" do
- @rack_context.should_receive(:getInitParameter).with("rails.root").and_return "/WEB-INF"
- @rack_context.should_receive(:getRealPath).with("/WEB-INF").and_return "./WEB-INF"
+ expect(@rack_context).to receive(:getInitParameter).with("rails.root").and_return "/WEB-INF"
+ expect(@rack_context).to receive(:getRealPath).with("/WEB-INF").and_return "./WEB-INF"
booter.boot!
- booter.app_path.should == "./WEB-INF"
+ expect(booter.app_path).to eq "./WEB-INF"
end
before do
@@ -40,68 +40,69 @@
end
it "should default rails path to /WEB-INF" do
- @rack_context.should_receive(:getRealPath).with("/WEB-INF").and_return "/usr/apps/WEB-INF"
+ expect(@rack_context).to receive(:getRealPath).with("/WEB-INF").and_return "/usr/apps/WEB-INF"
booter.boot!
- booter.app_path.should == "/usr/apps/WEB-INF"
+ expect(booter.app_path).to eq "/usr/apps/WEB-INF"
end
it "leaves ENV['RAILS_ENV'] as is if it was already set" do
ENV['RAILS_ENV'] = 'staging'
booter.boot!
- ENV['RAILS_ENV'].should == 'staging'
- booter.rails_env.should == "staging"
+ expect(ENV['RAILS_ENV']).to eq 'staging'
+ expect(booter.rails_env).to eq "staging"
end
it "determines RAILS_ENV from the 'rails.env' init parameter" do
ENV['RAILS_ENV'] = nil
- @rack_context.should_receive(:getInitParameter).with("rails.env").and_return "test"
+ expect(@rack_context).to receive(:getInitParameter).with("rails.env").and_return "test"
booter.boot!
- booter.rails_env.should == "test"
+ expect(booter.rails_env).to eq "test"
end
it "gets rails environment from rack environmnent" do
ENV.delete('RAILS_ENV')
ENV['RACK_ENV'] = 'development'
- @rack_context.stub(:getInitParameter)
+ allow(@rack_context).to receive(:getInitParameter)
booter.boot!
- booter.rails_env.should == 'development'
+ expect(booter.rails_env).to eq 'development'
end
it "default RAILS_ENV to 'production'" do
ENV.delete('RAILS_ENV'); ENV.delete('RACK_ENV')
booter.boot!
- booter.rails_env.should == "production"
+ expect(booter.rails_env).to eq "production"
end
it "should set RAILS_RELATIVE_URL_ROOT based on the servlet context path" do
- @rack_context.should_receive(:getContextPath).and_return '/myapp'
+ expect(@rack_context).to receive(:getContextPath).and_return '/myapp'
booter.boot!
- ENV['RAILS_RELATIVE_URL_ROOT'].should == '/myapp'
+ expect(ENV['RAILS_RELATIVE_URL_ROOT']).to eq '/myapp'
end
it "should append to RAILS_RELATIVE_URL_ROOT if 'rails.relative_url_append' is set" do
- @rack_context.should_receive(:getContextPath).and_return '/myapp'
- @rack_context.should_receive(:getInitParameter).with("rails.relative_url_append").and_return "/blah"
+ expect(@rack_context).to receive(:getContextPath).and_return '/myapp'
+ expect(@rack_context).to receive(:getInitParameter).with("rails.relative_url_append").and_return "/blah"
booter.boot!
- ENV['RAILS_RELATIVE_URL_ROOT'].should == '/myapp/blah'
+ expect(ENV['RAILS_RELATIVE_URL_ROOT']).to eq '/myapp/blah'
end
it "should determine the public html root from the 'public.root' init parameter" do
- @rack_context.should_receive(:getInitParameter).with("public.root").and_return "/blah"
- @rack_context.should_receive(:getRealPath).with("/blah").and_return "."
+ expect(@rack_context).to receive(:getInitParameter).with("public.root").and_return "/blah"
+ expect(@rack_context).to receive(:getRealPath).with("/blah").and_return "."
booter.boot!
- booter.public_path.should == "."
+ expect(booter.public_path).to eq "."
end
it "should default public root to '/'" do
- @rack_context.should_receive(:getRealPath).with("/").and_return "."
+ expect(@rack_context).to receive(:getRealPath).with("/").and_return "."
booter.boot!
- booter.public_path.should == "."
+ expect(booter.public_path).to eq "."
end
RAILS_ROOT_DIR = File.expand_path("../../../rails", __FILE__)
- describe "Rails (stubbed)", :lib => :stub do # NOTE: specs currently only test with a stubbed Rails::Railtie
+ describe "Rails (stubbed)", :lib => :stub do
+ # NOTE: specs currently only test with a stubbed Rails::Railtie
before :all do
$LOAD_PATH.unshift File.join(RAILS_ROOT_DIR, 'stub') # for require 'rails/railtie'
@@ -116,7 +117,7 @@
end
after :each do
- [ :app_path, :public_path, :context ].each do |name|
+ [:app_path, :public_path, :context].each do |name|
JRuby::Rack.send :remove_instance_variable, :"@#{name}"
end
end
@@ -128,41 +129,44 @@
let(:railtie_class) { Class.new(Rails::Railtie) }
it "should have loaded the railtie" do
- defined?(JRuby::Rack::Railtie).should_not be nil
+ expect(defined?(JRuby::Rack::Railtie)).not_to be nil
end
it "should set the application configuration's public path" do
paths = %w( public public/javascripts public/stylesheets ).inject({}) do
- |hash, path| hash[ path ] = [ File.join(RAILS_ROOT_DIR, path) ]; hash
+ |hash, path|
+ hash[path] = [File.join(RAILS_ROOT_DIR, path)]; hash
end
- app = double("app"); app.stub_chain(:config, :paths).and_return(paths)
+ app = double("app")
+ expect(app).to receive_message_chain(:config, :paths).and_return(paths)
public_path = Pathname.new(booter.public_path)
- railtie_class.config.__before_configuration.size.should == 1
+ expect(railtie_class.config.__before_configuration.size).to eq 1
before_config = railtie_class.config.__before_configuration.first
- before_config.should_not be nil
+ expect(before_config).not_to be nil
before_config.call(app)
- paths['public'].should == public_path.to_s
- paths['public/javascripts'].should == public_path.join("javascripts").to_s
- paths['public/stylesheets'].should == public_path.join("stylesheets").to_s
+ expect(paths['public']).to eq public_path.to_s
+ expect(paths['public/javascripts']).to eq public_path.join("javascripts").to_s
+ expect(paths['public/stylesheets']).to eq public_path.join("stylesheets").to_s
end
it "works when JRuby::Rack.public_path is nil (public does not exist)" do
paths = %w( public public/javascripts public/stylesheets ).inject({}) do
- |hash, path| hash[ path ] = [ path.sub('public', 'NO-SUCH-DiR') ]; hash
+ |hash, path|
+ hash[path] = [path.sub('public', 'NO-SUCH-DiR')]; hash
end
- app = double("app"); app.stub_chain(:config, :paths).and_return(paths)
+ app = double("app")
JRuby::Rack.public_path = nil
before_config = railtie_class.config.__before_configuration.first
- before_config.should_not be nil
+ expect(before_config).not_to be nil
before_config.call(app)
- paths['public'].should == [ public_path = "NO-SUCH-DiR" ]
- paths['public/javascripts'].should == [ File.join(public_path, "javascripts") ]
- paths['public/stylesheets'].should ==[ File.join(public_path, "stylesheets") ]
+ expect(paths['public']).to eq [public_path = "NO-SUCH-DiR"]
+ expect(paths['public/javascripts']).to eq [File.join(public_path, "javascripts")]
+ expect(paths['public/stylesheets']).to eq [File.join(public_path, "stylesheets")]
end
describe "logger" do
@@ -175,7 +179,8 @@
after(:all) do
if @active_support
- [:Logger, :TaggedLogging, :LoggerSilence, :LoggerThreadSafeLevel].each do |name| # stubbed bits we might end up loading
+ [:Logger, :TaggedLogging, :LoggerSilence, :LoggerThreadSafeLevel].each do |name|
+ # stubbed bits we might end up loading
ActiveSupport.send :remove_const, name unless @active_support.include?(name)
end
else
@@ -185,21 +190,26 @@
before do
@app = double "app"
- @app.stub(:config).and_return @config = double("config")
+ allow(@app).to receive(:config).and_return @config = double("config")
@config.instance_eval do
- def logger; @logger; end
- def logger=(logger); @logger = logger; end
+ def logger
+ @logger;
+ end
+
+ def logger=(logger)
+ ; @logger = logger;
+ end
end
end
it "has an initializer" do
- log_initializer.should_not be_nil
- log_initializer[1].should == [{:before => :initialize_logger}]
+ expect(log_initializer).not_to be_nil
+ expect(log_initializer[1]).to eq [{ :before => :initialize_logger }]
end
it "gets set as config.logger (wrapped with tagged logging and logger_silence)" do
- @config.stub(:log_level).and_return(nil)
- @config.stub(:log_formatter).and_return(nil)
+ allow(@config).to receive(:log_level).and_return(nil)
+ allow(@config).to receive(:log_formatter).and_return(nil)
log_initializer.last.call(@app)
rails_logger = @app.config.logger
@@ -221,8 +231,8 @@ def logger=(logger); @logger = logger; end
# def logger; @logger; end
# def logger=(logger); @logger = logger; end
# end
- @config.stub(:log_formatter).and_return(nil)
- @config.should_receive(:log_level).and_return(:error)
+ allow(@config).to receive(:log_formatter).and_return(nil)
+ expect(@config).to receive(:log_level).and_return(:error)
log_initializer.last.call(@app)
rails_logger = @app.config.logger
@@ -240,7 +250,7 @@ def log_initializer
it "should return the Rails.application instance" do
app = double "app"
Rails.application = app
- booter.to_app.should == app
+ expect(booter.to_app).to eq app
end
end # if defined? Rails
@@ -253,8 +263,8 @@ def log_initializer
let(:controller) do
controller = ActionController::Base.new
- controller.stub(:request).and_return request
- controller.stub(:response).and_return response
+ allow(controller).to receive(:request).and_return request
+ allow(controller).to receive(:response).and_return response
controller
end
@@ -265,26 +275,26 @@ def log_initializer
let(:servlet_response) { org.springframework.mock.web.MockHttpServletResponse.new }
before :each do
- request.stub(:env).and_return({
- 'java.servlet_request' => servlet_request,
- 'java.servlet_response' => servlet_response
- })
- response.stub(:headers).and_return @headers = {}
+ allow(request).to receive(:env).and_return({
+ 'java.servlet_request' => servlet_request,
+ 'java.servlet_response' => servlet_response
+ })
+ allow(response).to receive(:headers).and_return @headers = {}
end
it "should add a #servlet_request method to ActionController::Base" do
- controller.should respond_to(:servlet_request)
- controller.servlet_request.should == servlet_request
+ expect(controller).to respond_to(:servlet_request)
+ expect(controller.servlet_request).to eq servlet_request
end
it "should add a #servlet_response method to ActionController::Base" do
- controller.should respond_to(:servlet_response)
- controller.servlet_response.should == servlet_response
+ expect(controller).to respond_to(:servlet_response)
+ expect(controller.servlet_response).to eq servlet_response
end
it "should add a #forward_to method for forwarding to another servlet" do
#@servlet_response = double "servlet response"
- controller.request.should_receive(:forward_to).with("/forward.jsp")
+ expect(controller.request).to receive(:forward_to).with("/forward.jsp")
controller.forward_to '/forward.jsp'
end
diff --git a/src/spec/ruby/jruby/rack/response_spec.rb b/src/spec/ruby/jruby/rack/response_spec.rb
index 7de11aa0d..a1dd9b5a6 100644
--- a/src/spec/ruby/jruby/rack/response_spec.rb
+++ b/src/spec/ruby/jruby/rack/response_spec.rb
@@ -12,8 +12,8 @@
describe JRuby::Rack::Response do
let(:response) do
- status, headers, body = 200, { 'Content-Type' => 'bogus' }, [ '
Hello
' ]
- JRuby::Rack::Response.new [ status, headers, body ]
+ status, headers, body = 200, { 'Content-Type' => 'bogus' }, ['Hello
']
+ JRuby::Rack::Response.new [status, headers, body]
end
let(:servlet_response) { javax.servlet.http.HttpServletResponse.impl {} }
@@ -21,7 +21,7 @@
let(:response_environment) { new_response_environment(servlet_response) }
it "converts status to integer" do
- response = JRuby::Rack::Response.new [ '202', {}, [''] ]
+ response = JRuby::Rack::Response.new ['202', {}, ['']]
expect(response.to_java.getStatus).to eql 202
end
@@ -32,106 +32,108 @@
end
it "writes the status to the servlet response" do
- servlet_response.should_receive(:setStatus).with(200)
+ expect(servlet_response).to receive(:setStatus).with(200)
response.write_status(response_environment)
end
it "writes the headers to the servlet response" do
response.to_java.getHeaders.update({
- "Content-Type" => "text/html",
- "Content-Length" => '20',
- "Server" => "Apache/2.2.x"
- })
- servlet_response.should_receive(:setContentType).with("text/html")
- servlet_response.should_receive(:setContentLength).with(20)
- servlet_response.should_receive(:addHeader).with("Server", "Apache/2.2.x")
+ "Content-Type" => "text/html",
+ "Content-Length" => '20',
+ "Server" => "Apache/2.2.x"
+ })
+ expect(servlet_response).to receive(:setContentType).with("text/html")
+ expect(servlet_response).to receive(:setContentLength).with(20)
+ expect(servlet_response).to receive(:addHeader).with("Server", "Apache/2.2.x")
response.write_headers(response_environment)
end
it "accepts (non-array) body that responds to each" do
require 'stringio'
- response = JRuby::Rack::Response.new [ '202', {}, StringIO.new("1\n2\n3") ]
+ response = JRuby::Rack::Response.new ['202', {}, StringIO.new("1\n2\n3")]
expect(response.to_java.getBody).to eql "1\n2\n3"
end
it "writes headers with multiple values multiple addHeader invocations" do
response.to_java.getHeaders.update({
- "Content-Type" => "text/html",
- "Content-Length" => '20',
- "Set-Cookie" => %w(cookie1 cookie2)
- })
- servlet_response.should_receive(:setContentType).with("text/html")
- servlet_response.should_receive(:setContentLength).with(20)
- servlet_response.should_receive(:addHeader).with("Set-Cookie", "cookie1")
- servlet_response.should_receive(:addHeader).with("Set-Cookie", "cookie2")
+ "Content-Type" => "text/html",
+ "Content-Length" => '20',
+ "Set-Cookie" => %w(cookie1 cookie2)
+ })
+ expect(servlet_response).to receive(:setContentType).with("text/html")
+ expect(servlet_response).to receive(:setContentLength).with(20)
+ expect(servlet_response).to receive(:addHeader).with("Set-Cookie", "cookie1")
+ expect(servlet_response).to receive(:addHeader).with("Set-Cookie", "cookie2")
response.write_headers(response_environment)
end
it "writes headers whose value contains newlines as multiple addHeader invocations" do
response.to_java.getHeaders.update({ "Set-Cookie" => "cookie1\ncookie2" })
- servlet_response.should_receive(:addHeader).with("Set-Cookie", "cookie1")
- servlet_response.should_receive(:addHeader).with("Set-Cookie", "cookie2")
+ expect(servlet_response).to receive(:addHeader).with("Set-Cookie", "cookie1")
+ expect(servlet_response).to receive(:addHeader).with("Set-Cookie", "cookie2")
response.write_headers(response_environment)
end
it "writes headers whose value contains newlines as multiple addHeader invocations when string doesn't respond to #each" do
value = "cookie1\ncookie2"
- class << value; undef_method :each; end if value.respond_to?(:each)
+ class << value
+ undef_method :each;
+ end if value.respond_to?(:each)
response.to_java.getHeaders.update({ "Set-Cookie" => value })
- servlet_response.should_receive(:addHeader).with("Set-Cookie", "cookie1")
- servlet_response.should_receive(:addHeader).with("Set-Cookie", "cookie2")
+ expect(servlet_response).to receive(:addHeader).with("Set-Cookie", "cookie1")
+ expect(servlet_response).to receive(:addHeader).with("Set-Cookie", "cookie2")
response.write_headers(response_environment)
end
it "adds an int header when values is a fixnum" do
update_response_headers "Expires" => 0
- response_environment.should_receive(:addIntHeader).with("Expires", 0)
+ expect(response_environment).to receive(:addIntHeader).with("Expires", 0)
response.write_headers(response_environment)
end
it "adds date header when value is date" do
update_response_headers "Last-Modified" => time = Time.now
- millis = ( time.to_f * 1000.0 ).to_i
- servlet_response.should_receive(:addDateHeader).with("Last-Modified", millis)
+ millis = (time.to_f * 1000.0).to_i
+ expect(servlet_response).to receive(:addDateHeader).with("Last-Modified", millis)
response.write_headers(response_environment)
end
it "writes the status first, followed by headers, and body last" do
- servlet_response.should_receive(:isCommitted).and_return false
- response.should_receive(:write_status).ordered
- response.should_receive(:write_headers).ordered
- response.should_receive(:write_body).ordered
+ expect(servlet_response).to receive(:isCommitted).and_return false
+ expect(response).to receive(:write_status).ordered
+ expect(response).to receive(:write_headers).ordered
+ expect(response).to receive(:write_body).ordered
response.to_java.respond(response_environment)
end
it "does not write status, headers or body if the request is committed (was forwarded)" do
- servlet_response.should_receive(:isCommitted).and_return true
+ expect(servlet_response).to receive(:isCommitted).and_return true
response.to_java.respond(response_environment)
end
it "calls close on the body if the body responds to close" do
body = double('body')
- body.should_receive(:each).ordered.and_yield "hello"
- body.should_receive(:close).ordered
- response = JRuby::Rack::Response.new [ '200', {}, body ]
+ expect(body).to receive(:each).ordered.and_yield "hello"
+ expect(body).to receive(:close).ordered
+ response = JRuby::Rack::Response.new ['200', {}, body]
response.to_java.getBody
end
it "detects a chunked response when the Transfer-Encoding header is set" do
headers = { "Transfer-Encoding" => "chunked" }
- response = JRuby::Rack::Response.new [ 200, headers, ['body'] ]
+ response = JRuby::Rack::Response.new [200, headers, ['body']]
# NOTE: servlet container auto handle chunking when flushed no need to set :
- servlet_response.should_not_receive(:addHeader).with("Transfer-Encoding", "chunked")
+ expect(servlet_response).not_to receive(:addHeader).with("Transfer-Encoding", "chunked")
response.write_headers(response_environment)
- expect( response.chunked? ).to be true
+ expect(response.chunked?).to be true
end
describe "#write_body" do
let(:stream) do
stream = StubOutputStream.new
- response_environment.stub(:getOutputStream).and_return stream
+ allow(response_environment).to receive(:getOutputStream).and_return stream
stream
end
@@ -139,20 +141,20 @@ class << value; undef_method :each; end if value.respond_to?(:each)
it "writes the body to the stream and flushes when the response is chunked" do
headers = { "Transfer-Encoding" => "chunked" }
- response = JRuby::Rack::Response.new [ 200, headers, ['hello', 'there'] ]
- stream.should_receive(:write).exactly(2).times
- stream.should_receive(:flush).exactly(2).times
+ response = JRuby::Rack::Response.new [200, headers, ['hello', 'there']]
+ expect(stream).to receive(:write).exactly(2).times
+ expect(stream).to receive(:flush).exactly(2).times
# NOTE: servlet container auto handle chunking when flushed no need to set :
- response_environment.should_not_receive(:addHeader).with("Transfer-Encoding", "chunked")
+ expect(response_environment).not_to receive(:addHeader).with("Transfer-Encoding", "chunked")
response.write_headers(response_environment)
- expect( response.chunked? ).to be true
+ expect(response.chunked?).to be true
response.write_body(response_environment)
end
it "dechunks the body when a chunked response is detected",
- :lib => [ :rails23, :rails31, :rails32, :rails40 ] do
+ :lib => [:rails23, :rails31, :rails32, :rails40] do
require 'rack/chunked'
headers = {
@@ -171,32 +173,32 @@ class << value; undef_method :each; end if value.respond_to?(:each)
with_dechunk do
body = Rack::Chunked::Body.new body
- response = JRuby::Rack::Response.new([ 200, headers, body ])
+ response = JRuby::Rack::Response.new([200, headers, body])
response.write_headers(response_environment)
times = 0
- stream.should_receive(:write).exactly(6).times do |bytes|
+ expect(stream).to receive(:write).exactly(6).times do |bytes|
str = String.from_java_bytes(bytes)
str = str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
case times += 1
- when 1 then str.should == "1"
- when 2 then str.should == "\nsecond chunk"
- when 3 then str.should == "a multi\nline chunk \n42"
- when 4 then str.should == "utf-8 chunk 'ty píčo'!\n"
- when 5 then str.should == "terminated chunk\r\n"
- when 6 then str.should == "\r\nthe very\r\n last\r\n\r\n chunk"
+ when 1 then expect(str).to eq "1"
+ when 2 then expect(str).to eq "\nsecond chunk"
+ when 3 then expect(str).to eq "a multi\nline chunk \n42"
+ when 4 then expect(str).to eq "utf-8 chunk 'ty píčo'!\n"
+ when 5 then expect(str).to eq "terminated chunk\r\n"
+ when 6 then expect(str).to eq "\r\nthe very\r\n last\r\n\r\n chunk"
else
fail("unexpected :write received with #{str.inspect}")
end
end
- stream.should_receive(:flush).exactly(6+1).times # +1 for tail chunk
+ expect(stream).to receive(:flush).exactly(6 + 1).times # +1 for tail chunk
response.write_body(response_environment)
end
end
it "does not dechunk body when dechunkins is turned off",
- :lib => [ :rails31, :rails32, :rails40 ] do
+ :lib => [:rails31, :rails32, :rails40] do
dechunk = JRuby::Rack::Response.dechunk?
begin
JRuby::Rack::Response.dechunk = false
@@ -212,22 +214,22 @@ class << value; undef_method :each; end if value.respond_to?(:each)
""
]
body = Rack::Chunked::Body.new body
- response = JRuby::Rack::Response.new([ 200, headers, body ])
+ response = JRuby::Rack::Response.new([200, headers, body])
response.write_headers(response_environment)
times = 0
- stream.should_receive(:write).exactly(3).times do |bytes|
+ expect(stream).to receive(:write).exactly(3).times do |bytes|
str = String.from_java_bytes(bytes)
case times += 1
- when 1 then str.should == "1\r\n1\r\n"
- when 2 then str.should == "d\r\n\nsecond chunk\r\n"
- when 3 then str.should == "0\r\n\r\n"
+ when 1 then expect(str).to eq "1\r\n1\r\n"
+ when 2 then expect(str).to eq "d\r\n\nsecond chunk\r\n"
+ when 3 then expect(str).to eq "0\r\n\r\n"
else
fail("unexpected :write received with #{str.inspect}")
end
end
- stream.should_receive(:flush).exactly(3).times
+ expect(stream).to receive(:flush).exactly(3).times
response.write_body(response_environment)
@@ -247,137 +249,156 @@ class << value; undef_method :each; end if value.respond_to?(:each)
"7\r\nty píčo\r\n", # " incorrect bytesize (9)
"21\r\n a chunk with an invalid length \r\n" # size == 32 (0x20)
]
- response = JRuby::Rack::Response.new([ 200, headers, body ])
+ response = JRuby::Rack::Response.new([200, headers, body])
response.write_headers(response_environment)
times = 0
- stream.should_receive(:write).exactly(5).times do |bytes|
+ expect(stream).to receive(:write).exactly(5).times do |bytes|
str = String.from_java_bytes(bytes)
case times += 1
- when 1 then str.should == "1"
- when 2 then str.should == "a multi\nline chunk \n42"
- when 3 then str.should == "\r\nthe very\r\n last\r\n\r\n chunk"
+ when 1 then expect(str).to eq "1"
+ when 2 then expect(str).to eq "a multi\nline chunk \n42"
+ when 3 then expect(str).to eq "\r\nthe very\r\n last\r\n\r\n chunk"
when 4 then
str = str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
- str.should == "7\r\nty píčo\r\n"
- when 5 then str.should == "21\r\n a chunk with an invalid length \r\n"
+ expect(str).to eq "7\r\nty píčo\r\n"
+ when 5 then expect(str).to eq "21\r\n a chunk with an invalid length \r\n"
else
fail("unexpected :write received with #{str.inspect}")
end
end
- stream.should_receive(:flush).exactly(5).times
+ expect(stream).to receive(:flush).exactly(5).times
response.write_body(response_environment)
end
it "flushes the body (parts) when no content-length set" do
- response = JRuby::Rack::Response.new [ 200, {}, [ 'hello', 'there' ] ]
+ response = JRuby::Rack::Response.new [200, {}, ['hello', 'there']]
response.write_headers(response_environment)
- stream.should_receive(:write).once.ordered
- stream.should_receive(:flush).once.ordered
- stream.should_receive(:write).once.ordered
- stream.should_receive(:flush).once.ordered
+ expect(stream).to receive(:write).once.ordered
+ expect(stream).to receive(:flush).once.ordered
+ expect(stream).to receive(:write).once.ordered
+ expect(stream).to receive(:flush).once.ordered
response.write_body(response_environment)
end
it "does not flush the body when content-length set" do
headers = { "Content-Length" => 10 }
- response = JRuby::Rack::Response.new [ 200, headers, [ 'hello', 'there' ] ]
+ response = JRuby::Rack::Response.new [200, headers, ['hello', 'there']]
response.write_headers(response_environment)
- #stream.should_receive(:write).twice
- stream.should_receive(:flush).never
+ # expect(stream).to receive(:write).twice
+ expect(stream).to receive(:flush).never
response.write_body(response_environment)
end
it "writes the body to the servlet response" do
- response = JRuby::Rack::Response.new [ 200, {}, [ '1', '2', '3' ] ]
+ response = JRuby::Rack::Response.new [200, {}, ['1', '2', '3']]
- stream.should_receive(:write).exactly(3).times
+ expect(stream).to receive(:write).exactly(3).times
response.write_body(response_environment)
end
it "calls close on the body if the body responds to close" do
body = double('body')
- body.should_receive(:each).ordered.and_yield("hello").and_yield("there")
- body.should_receive(:close).ordered
- response = JRuby::Rack::Response.new [ 200, {}, body ]
+ expect(body).to receive(:each).ordered.and_yield("hello").and_yield("there")
+ expect(body).to receive(:close).ordered
+ response = JRuby::Rack::Response.new [200, {}, body]
- stream.should_receive(:write).exactly(2).times
+ expect(stream).to receive(:write).exactly(2).times
response.write_body(response_environment)
end
-# it "yields the stream to an object that responds to #call" do
-# body = Proc.new { |stream| stream.write '42'.to_java_bytes }
-# response = JRuby::Rack::Response.new [ 200, {}, body ]
-#
-# stream.should_receive(:write).with('42').once
-# response.write_body(response_environment)
-# end
+ # it "yields the stream to an object that responds to #call" do
+ # body = Proc.new { |stream| stream.write '42'.to_java_bytes }
+ # response = JRuby::Rack::Response.new [ 200, {}, body ]
+ #
+ # expect(stream).to receive(:write).with('42').once
+ # response.write_body(response_environment)
+ # end
it "does not yield the stream if the object responds to both #call and #each" do
- response = JRuby::Rack::Response.new [ 200, {}, body = ['body'] ]
- def body.call; raise 'yielded' end
+ response = JRuby::Rack::Response.new [200, {}, body = ['body']]
- stream.should_receive(:write)
+ def body.call
+ raise 'yielded'
+ end
+
+ expect(stream).to receive(:write)
response.write_body(response_environment)
end
it "writes a (Tempfile) stream using a channel" do
- body = ( require 'tempfile'; Tempfile.new 'to_channel_spec' )
+ body = (require 'tempfile'; Tempfile.new 'to_channel_spec')
body << "1234567890"; body << "\n"; body << '1234567890'; body.rewind
- def body.each; raise "each not-expected"; end
- def body.each_line; raise "each_line not-expected"; end
- class << body; undef_method :to_path; end if body.respond_to?(:to_path)
- response = JRuby::Rack::Response.new [ 200, {}, body ]
+ def body.each
+ raise "each not-expected";
+ end
+
+ def body.each_line
+ raise "each_line not-expected";
+ end
+
+ class << body
+ undef_method :to_path;
+ end if body.respond_to?(:to_path)
+
+ response = JRuby::Rack::Response.new [200, {}, body]
response.write_body(response_environment)
- expect( stream.to_s ).to eql "1234567890\n1234567890"
+ expect(stream.to_s).to eql "1234567890\n1234567890"
expect { body.to_channel }.to raise_error IOError, /closed/
end
it "writes a (StringIO) stream using a channel" do
- body = ( require 'stringio'; StringIO.new '' )
+ body = (require 'stringio'; StringIO.new '')
body << "1234567890"; body << "\n"; body << '1234567890'; body.rewind
- def body.each; raise "each not-expected"; end
- def body.each_line; raise "each_line not-expected"; end
- response = JRuby::Rack::Response.new [ 200, {}, body ]
+ def body.each
+ raise "each not-expected";
+ end
+
+ def body.each_line
+ raise "each_line not-expected";
+ end
+
+ response = JRuby::Rack::Response.new [200, {}, body]
response.write_body(response_environment)
- expect( stream.to_s ).to eql "1234567890\n1234567890"
+ expect(stream.to_s).to eql "1234567890\n1234567890"
expect { body.to_channel }.not_to raise_error
end
it "streams a file using a channel if wrapped in body_parts",
- :lib => [ :rails30, :rails31, :rails32 ] do
+ :lib => [:rails30, :rails31, :rails32] do
body = wrap_file_body path =
- File.expand_path('../../files/image.jpg', File.dirname(__FILE__))
+ File.expand_path('../../files/image.jpg', File.dirname(__FILE__))
stream = self.stream
- response = JRuby::Rack::Response.new [ 200, body.headers, body ]
+ response = JRuby::Rack::Response.new [200, body.headers, body]
response.write_body(response_environment)
expect_eql_java_bytes stream.to_java_bytes, File.read(path).to_java_bytes
end
- it "closes original body during write_body", :lib => [ :rails30, :rails31, :rails32 ] do
+ it "closes original body during write_body", :lib => [:rails30, :rails31, :rails32] do
body = wrap_file_body File.expand_path('../../files/image.jpg', File.dirname(__FILE__))
- response = JRuby::Rack::Response.new [ 200, body.headers, body ]
- body.should_receive(:close)
+ response = JRuby::Rack::Response.new [200, body.headers, body]
+ expect(body).to receive(:close)
response.write_body(response_environment)
end
private
- def wrap_file_body(path) # Rails style when doing #send_file
+ def wrap_file_body(path)
+ # Rails style when doing #send_file
require 'action_dispatch/http/response'
file = File.open(path, 'rb')
@@ -397,10 +418,10 @@ def wrap_file_body(path) # Rails style when doing #send_file
it "sends a file when file (body) response detected" do
path = File.expand_path('../../files/image.jpg', File.dirname(__FILE__))
- response = JRuby::Rack::Response.new [ 200, {}, FileBody.new(path) ]
- response.should_receive(:send_file) do |path, response|
- expect( path ).to eql path
- expect( response).to be response_environment
+ response = JRuby::Rack::Response.new [200, {}, FileBody.new(path)]
+ expect(response).to receive(:send_file) do |path, response|
+ expect(path).to eql path
+ expect(response).to be response_environment
end
response.write_body(response_environment)
end
@@ -426,7 +447,7 @@ def each
end
it "swallows client abort exceptions by default" do
- response_environment.stub(:getOutputStream).and_return BrokenPipeOutputStream.new
+ allow(response_environment).to receive(:getOutputStream).and_return BrokenPipeOutputStream.new
with_swallow_client_abort do
response.write_body response_environment
end
@@ -434,35 +455,39 @@ def each
class BrokenPipeOutputStream < StubOutputStream
- def flush; raise java.io.EOFException.new 'broken pipe' end
+ def flush
+ raise java.io.EOFException.new 'broken pipe'
+ end
end
it "raises client abort exceptions if not set to swallow" do
- response_environment.stub(:getOutputStream).and_return BrokenPipeOutputStream.new
+ allow(response_environment).to receive(:getOutputStream).and_return BrokenPipeOutputStream.new
begin
with_swallow_client_abort(false) do
response.write_body response_environment
end
fail 'EOF exception NOT raised!'
rescue java.io.IOException => e
- e.to_s.should =~ /broken pipe/i
+ expect(e.to_s).to match(/broken pipe/i)
end
end
it "raises exceptions that do not look like abort exceptions" do
- response_environment.stub(:getOutputStream).and_return BrokenCigarOutputStream.new
+ allow(response_environment).to receive(:getOutputStream).and_return BrokenCigarOutputStream.new
begin
response.write_body response_environment
fail 'IO exception NOT raised!'
rescue java.io.IOException => e
- e.to_s.should =~ /broken cigar/i
+ expect(e.to_s).to match(/broken cigar/i)
end
end
class BrokenCigarOutputStream < StubOutputStream
- def flush; raise java.io.IOException.new 'broken cigar' end
+ def flush
+ raise java.io.IOException.new 'broken cigar'
+ end
end
diff --git a/src/spec/ruby/jruby/rack/servlet_ext_spec.rb b/src/spec/ruby/jruby/rack/servlet_ext_spec.rb
index 17dcae191..1742adde4 100644
--- a/src/spec/ruby/jruby/rack/servlet_ext_spec.rb
+++ b/src/spec/ruby/jruby/rack/servlet_ext_spec.rb
@@ -8,154 +8,154 @@
require File.expand_path('spec_helper', File.dirname(__FILE__) + '/../..')
describe 'servlet-ext' do
-
+
before(:all) { require 'jruby/rack/servlet_ext' }
-
+
shared_examples_for "hash" do
-
+
it "returns attributes from []" do
subject.setAttribute('foo', 'bar')
- subject["foo"].should == "bar"
-
+ expect(subject["foo"]).to eq("bar")
+
subject.setAttribute('bar', 42)
- subject[:bar].should == 42
+ expect(subject[:bar]).to eq(42)
end
it "sets attributes with []=" do
subject["muu"] = hash = { :huu => 'HU!' }
- subject.getAttribute('muu').should be hash
-
+ expect(subject.getAttribute('muu')).to be(hash)
+
subject[:num] = 12
- subject.getAttribute('num').should == 12
+ expect(subject.getAttribute('num')).to eq(12)
end
it "deletes attributes" do
subject.setAttribute('foo', 'bar')
subject.setAttribute('xxx', 12345)
-
+
subject.delete('foo')
- subject.getAttribute('muu').should be nil
+ expect(subject.getAttribute('muu')).to be_nil
+
+ expect { subject.delete('yyy') }.not_to raise_error
- lambda { subject.delete('yyy') }.should_not raise_error
-
- subject.getAttributeNames.to_a.should include('xxx')
+ expect(subject.getAttributeNames.to_a).to include('xxx')
subject.delete(:xxx)
- subject.getAttributeNames.to_a.should_not include('xxx')
+ expect(subject.getAttributeNames.to_a).not_to include('xxx')
end
it "reports (string) keys" do
- subject.keys.should == []
+ expect(subject.keys).to eq([])
subject.setAttribute('foo', 'muu')
subject.setAttribute('bar', 12345)
-
- subject.keys.should == [ 'foo', 'bar' ]
+
+ expect(subject.keys).to eq(['foo', 'bar'])
end
it "reports values" do
- subject.values.should == []
+ expect(subject.values).to eq([])
subject.setAttribute('foo', 'muu')
subject.setAttribute('bar', 12345)
-
- subject.values.should == [ 'muu', 12345 ]
+
+ expect(subject.values).to eq(['muu', 12345])
end
it "yields attribute pairs on each" do
subject.setAttribute('foo', 'muu')
subject.setAttribute('bar', 12345)
-
+
count = 0
subject.each do |key, val|
case count += 1
when 1 then
- key.should == 'foo'
- val.should == 'muu'
+ expect(key).to eq('foo')
+ expect(val).to eq('muu')
when 2 then
- key.should == 'bar'
- val.should == 12345
+ expect(key).to eq('bar')
+ expect(val).to eq(12345)
else
fail "unexpected #{count}. yield with (#{key.inspect}, #{val.inspect})"
end
end
end
-
+
end
-
+
describe Java::JavaxServlet::ServletContext do
- let(:subject) do
+ let(:subject) do
context = org.springframework.mock.web.MockServletContext.new
context.removeAttribute("javax.servlet.context.tempdir")
context
end
it_behaves_like "hash"
-
+
end
-
+
describe Java::JavaxServlet::ServletRequest do
-
+
before :each do
@request = Java::JavaxServlet::ServletRequest.impl {}
end
it "should allow #[] to access request attributes" do
- @request.should_receive(:getAttribute).with("HA!").and_return "NYAH!"
- @request["HA!"].should == "NYAH!"
+ expect(@request).to receive(:getAttribute).with("HA!").and_return "NYAH!"
+ expect(@request["HA!"]).to eq("NYAH!")
end
it "should stringify the key, allowing symbols to be used as keys" do
- @request.should_receive(:getAttribute).with("foo").and_return "bar"
- @request[:foo].should == "bar"
+ expect(@request).to receive(:getAttribute).with("foo").and_return "bar"
+ expect(@request[:foo]).to eq("bar")
end
it "should allow #[]= to set request attributes" do
- @request.should_receive(:setAttribute).with("HA!", "NYAH!")
+ expect(@request).to receive(:setAttribute).with("HA!", "NYAH!")
@request["HA!"] = "NYAH!"
end
it "should give an array of keys from getAttributeNames" do
names = %w(a b c)
- @request.should_receive(:getAttributeNames).and_return names
- @request.keys.should == names
+ expect(@request).to receive(:getAttributeNames).and_return names
+ expect(@request.keys).to eq(names)
end
let(:subject) { org.springframework.mock.web.MockHttpServletRequest.new }
it_behaves_like "hash"
-
+
end
describe Java::JavaxServletHttp::HttpSession do
-
+
before :each do
@session = Java::JavaxServletHttp::HttpSession.impl {}
end
it "should allow #[] to access session attributes" do
- @session.should_receive(:getAttribute).with("HA!").and_return "NYAH!"
- @session["HA!"].should == "NYAH!"
+ expect(@session).to receive(:getAttribute).with("HA!").and_return "NYAH!"
+ expect(@session["HA!"]).to eq("NYAH!")
end
it "should stringify the key, allowing symbols to be used as keys" do
- @session.should_receive(:getAttribute).with("foo").and_return "bar"
- @session[:foo].should == "bar"
+ expect(@session).to receive(:getAttribute).with("foo").and_return "bar"
+ expect(@session[:foo]).to eq("bar")
end
it "should allow #[]= to set session attributes" do
- @session.should_receive(:setAttribute).with("HA!", "NYAH!")
+ expect(@session).to receive(:setAttribute).with("HA!", "NYAH!")
@session["HA!"] = "NYAH!"
end
it "should give an array of keys from getAttributeNames" do
names = %w(a b c)
- @session.should_receive(:getAttributeNames).and_return names
- @session.keys.should == names
+ expect(@session).to receive(:getAttributeNames).and_return names
+ expect(@session.keys).to eq(names)
end
-
+
let(:subject) { org.springframework.mock.web.MockHttpSession.new }
it_behaves_like "hash"
-
+
end
-
+
end
diff --git a/src/spec/ruby/rack/adapter/rails_spec.rb b/src/spec/ruby/rack/adapter/rails_spec.rb
index c62ae5f12..4958ae4f5 100644
--- a/src/spec/ruby/rack/adapter/rails_spec.rb
+++ b/src/spec/ruby/rack/adapter/rails_spec.rb
@@ -9,18 +9,18 @@
require 'action_controller' if defined? Rails
-#if defined? ActionController::Base.session_options # :rails23
+# if defined? ActionController::Base.session_options # :rails23
# # avoid ArgumentError with real 2.3 (default) middleware-stack :
# # A key is required to write a cookie containing the session data.
# # Use config.action_controller.session = ... in config/environment.rb
# ActionController::Base.session_options.update({
# :key => "_testapp_session", :secret => "some secret phrase" * 42
# })
-#else # :stub
+# else # :stub
# module ActionController
# class Base; end
# end
-#end
+# end
require 'rack/adapter/rails'
@@ -30,54 +30,59 @@
# avoid ArgumentError with real 2.3 (default) middleware-stack :
# A key is required to write a cookie containing the session data.
# Use config.action_controller.session = ... in config/environment.rb
- ActionController::Base.session_options.update({
- :key => "_testapp_session", :secret => "some secret phrase" * 42
- })
+ ActionController::Base.session_options.update(
+ {
+ :key => "_testapp_session", :secret => "some secret phrase" * 42
+ })
end
before :each do
- ActionController::Base.stub(:page_cache_extension).and_return ".html"
+ allow(ActionController::Base).to receive(:page_cache_extension).and_return ".html"
@rails = Rack::Adapter::Rails.new
- class << @rails; public :instance_variable_set; end
+
+ class << @rails
+ public :instance_variable_set;
+ end
+
@file_server = double "file server"
- @file_server.stub(:root).and_return "/tmp/root/public"
+ allow(@file_server).to receive(:root).and_return "/tmp/root/public"
@rails.instance_variable_set "@file_server", @file_server
@env = {}
end
it "should serve a static file first if it exists" do
- File.should_receive(:file?).with("/tmp/root/public/index.html").and_return true
- File.should_receive(:readable?).with("/tmp/root/public/index.html").and_return true
- @file_server.should_receive(:call).and_return [200, {}, ""]
+ expect(File).to receive(:file?).with("/tmp/root/public/index.html").and_return true
+ expect(File).to receive(:readable?).with("/tmp/root/public/index.html").and_return true
+ expect(@file_server).to receive(:call).and_return [200, {}, ""]
@env["PATH_INFO"] = "index.html"
- @rails.call(@env).should == [200, {}, ""]
+ expect(@rails.call(@env)).to eq [200, {}, ""]
end
it "should serve a static file with the page cache extension second if it exists" do
- File.should_receive(:file?).with("/tmp/root/public/index").and_return false
- File.should_receive(:file?).with("/tmp/root/public/index.html").and_return true
- File.should_receive(:readable?).with("/tmp/root/public/index.html").and_return true
- @file_server.should_receive(:call).and_return [200, {}, ""]
+ expect(File).to receive(:file?).with("/tmp/root/public/index").and_return false
+ expect(File).to receive(:file?).with("/tmp/root/public/index.html").and_return true
+ expect(File).to receive(:readable?).with("/tmp/root/public/index.html").and_return true
+ expect(@file_server).to receive(:call).and_return [200, {}, ""]
@env["PATH_INFO"] = "index"
- @rails.call(@env).should == [200, {}, ""]
- @env["PATH_INFO"].should == "index.html"
+ expect(@rails.call(@env)).to eq [200, {}, ""]
+ expect(@env["PATH_INFO"]).to eq "index.html"
end
it "should serve Rails last if no static files are found for the request" do
- File.should_receive(:file?).with("/tmp/root/public/index").and_return false
- File.should_receive(:file?).with("/tmp/root/public/index.html").and_return false
- @rails.should_receive(:serve_rails).and_return [200, {}, ""]
+ expect(File).to receive(:file?).with("/tmp/root/public/index").and_return false
+ expect(File).to receive(:file?).with("/tmp/root/public/index.html").and_return false
+ expect(@rails).to receive(:serve_rails).and_return [200, {}, ""]
@env["PATH_INFO"] = "index"
- @rails.call(@env).should == [200, {}, ""]
+ expect(@rails.call(@env)).to eq [200, {}, ""]
end
it "should not look for static files if 'jruby.rack.dynamic.requests.only' is present in the environment" do
- @rails.should_receive(:serve_rails).and_return [200, {}, ""]
+ expect(@rails).to receive(:serve_rails).and_return [200, {}, ""]
@env["jruby.rack.dynamic.requests.only"] = true
- @rails.call(@env).should == [200, {}, ""]
+ expect(@rails.call(@env)).to eq [200, {}, ""]
end
end if defined? ActionController::Base.session_options # :rails23
@@ -88,58 +93,58 @@ class << @rails; public :instance_variable_set; end
before :each do
@request, @response = double("request"), double("response")
- @request.stub(:env).and_return({"REQUEST_METHOD" => "GET"})
- @request.stub(:body).and_return ""
+ allow(@request).to receive(:env).and_return({ "REQUEST_METHOD" => "GET" })
+ allow(@request).to receive(:body).and_return ""
@wrapper = Rack::Adapter::RailsCgi::CGIWrapper.new(@request, @response)
end
it "should set the Content-Type from the 'type' key in the options" do
- options = {'type' => 'text/xml'}
- @response.should_receive(:[]=).with('Content-Type', options['type'])
+ options = { 'type' => 'text/xml' }
+ expect(@response).to receive(:[]=).with('Content-Type', options['type'])
@wrapper.header(options)
end
it "should set the Content-Length if present" do
- options = {'Content-Length' => 10}
- @response.should_receive(:[]=).with('Content-Type', 'text/html')
- @response.should_receive(:[]=).with('Content-Length', '10')
+ options = { 'Content-Length' => 10 }
+ expect(@response).to receive(:[]=).with('Content-Type', 'text/html')
+ expect(@response).to receive(:[]=).with('Content-Length', '10')
@wrapper.header(options)
end
it "should set the Content-Language and Expires from language and expires options" do
- options = {'language' => 'en', 'expires' => 'soon'}
- @response.should_receive(:[]=).with('Content-Type', 'text/html')
- @response.should_receive(:[]=).with('Content-Language', 'en')
- @response.should_receive(:[]=).with('Expires', 'soon')
+ options = { 'language' => 'en', 'expires' => 'soon' }
+ expect(@response).to receive(:[]=).with('Content-Type', 'text/html')
+ expect(@response).to receive(:[]=).with('Content-Language', 'en')
+ expect(@response).to receive(:[]=).with('Expires', 'soon')
@wrapper.header(options)
end
it "should set the status from the status option" do
- options = {'Status' => '200'}
- @response.should_receive(:[]=).with('Content-Type', 'text/html')
- @response.should_receive(:status=).with('200')
+ options = { 'Status' => '200' }
+ expect(@response).to receive(:[]=).with('Content-Type', 'text/html')
+ expect(@response).to receive(:status=).with('200')
@wrapper.header(options)
end
it "should set cookies as an array of strings in the Set-Cookie header" do
- options = {'cookie' => %w(a b c d)}
- @response.should_receive(:[]=).with('Content-Type', 'text/html')
- @response.should_receive(:[]=).with('Set-Cookie', options['cookie'])
+ options = { 'cookie' => %w(a b c d) }
+ expect(@response).to receive(:[]=).with('Content-Type', 'text/html')
+ expect(@response).to receive(:[]=).with('Set-Cookie', options['cookie'])
@wrapper.header(options)
end
it "should not set the Set-Cookie header if the cookie option is an empty array" do
- options = {'cookie' => []}
- @response.should_receive(:[]=).with('Content-Type', 'text/html')
- @response.should_not_receive(:[]=).with('Set-Cookie', anything())
+ options = { 'cookie' => [] }
+ expect(@response).to receive(:[]=).with('Content-Type', 'text/html')
+ expect(@response).not_to receive(:[]=).with('Set-Cookie', anything())
@wrapper.header(options)
end
it "should pass any other options through as headers" do
- options = {'blah' => '200', 'bza' => 'hey'}
- @response.should_receive(:[]=).with('Content-Type', 'text/html')
- @response.should_receive(:[]=).with('blah', '200')
- @response.should_receive(:[]=).with('bza', 'hey')
+ options = { 'blah' => '200', 'bza' => 'hey' }
+ expect(@response).to receive(:[]=).with('Content-Type', 'text/html')
+ expect(@response).to receive(:[]=).with('blah', '200')
+ expect(@response).to receive(:[]=).with('bza', 'hey')
@wrapper.header(options)
end
diff --git a/src/spec/ruby/rack/application_spec.rb b/src/spec/ruby/rack/application_spec.rb
index a41ba42e9..28311e4ac 100644
--- a/src/spec/ruby/rack/application_spec.rb
+++ b/src/spec/ruby/rack/application_spec.rb
@@ -17,16 +17,16 @@
it "invokes the call method on the ruby object and returns the rack response" do
rack_app = double "application"
- rack_app.should_receive(:call).with(@rack_env).and_return(@rack_response)
+ expect(rack_app).to receive(:call).with(@rack_env).and_return(@rack_response)
application = org.jruby.rack.DefaultRackApplication.new
application.setApplication(rack_app)
- application.call(@rack_env).should == @rack_response
+ expect(application.call(@rack_env)).to eq @rack_response
end
let(:servlet_context) do
servlet_context = double("servlet_context")
- servlet_context.stub(:getInitParameter) do |name|
+ allow(servlet_context).to receive(:getInitParameter) do |name|
name && nil # return null
end
servlet_context
@@ -75,18 +75,18 @@
end
def it_should_rewind_body
- content = ( "Answer to the Ultimate Question of Life, the Universe, " <<
- "and Everything ...\n" ) * 42
+ content = ("Answer to the Ultimate Question of Life, the Universe, " <<
+ "and Everything ...\n") * 42
servlet_request.setContent content.to_java_bytes
rack_app = double "application"
- rack_app.should_receive(:call) do |env|
+ expect(rack_app).to receive(:call) do |env|
body = JRuby::Rack::Input.new(env)
- body.read.should == content
- body.read.should == ""
+ expect(body.read).to eq content
+ expect(body.read).to eq ""
body.rewind
- body.read.should == content
+ expect(body.read).to eq content
org.jruby.rack.RackResponse.impl {}
end
@@ -107,58 +107,58 @@ def it_should_rewind_body
end
it "should receive a rackup script via the 'rackup' parameter" do
- @rack_config.should_receive(:getRackup).and_return 'run MyRackApp'
+ expect(@rack_config).to receive(:getRackup).and_return 'run MyRackApp'
@app_factory.init @rack_context
- @app_factory.rackup_script.should == 'run MyRackApp'
+ expect(@app_factory.rackup_script).to eq 'run MyRackApp'
end
it "should look for a rackup script via the 'rackup.path' parameter" do
- @rack_config.should_receive(:getRackupPath).and_return '/WEB-INF/hello.ru'
- @rack_context.should_receive(:getResourceAsStream).with('/WEB-INF/hello.ru').
+ expect(@rack_config).to receive(:getRackupPath).and_return '/WEB-INF/hello.ru'
+ expect(@rack_context).to receive(:getResourceAsStream).with('/WEB-INF/hello.ru').
and_return StubInputStream.new("run MyRackApp")
@app_factory.init @rack_context
- @app_factory.rackup_script.should == 'run MyRackApp'
+ expect(@app_factory.rackup_script).to eq 'run MyRackApp'
end
it "should look for a config.ru rackup script below /WEB-INF" do
- @rack_context.should_receive(:getResourcePaths).with('/WEB-INF/').and_return(
- java.util.HashSet.new(%w(app/ config/ config.ru lib/ vendor/).map{|f| "/WEB-INF/#{f}"}))
- @rack_context.should_receive(:getRealPath).with('/WEB-INF/config.ru')
- @rack_context.should_receive(:getResourceAsStream).with('/WEB-INF/config.ru').
+ expect(@rack_context).to receive(:getResourcePaths).with('/WEB-INF/').and_return(
+ java.util.HashSet.new(%w(app/ config/ config.ru lib/ vendor/).map { |f| "/WEB-INF/#{f}" }))
+ expect(@rack_context).to receive(:getRealPath).with('/WEB-INF/config.ru')
+ expect(@rack_context).to receive(:getResourceAsStream).with('/WEB-INF/config.ru').
and_return StubInputStream.new("run MyRackApp")
@app_factory.init @rack_context
- @app_factory.rackup_script.should == 'run MyRackApp'
+ expect(@app_factory.rackup_script).to eq 'run MyRackApp'
end
it "should look for a config.ru script in subdirectories of /WEB-INF" do
- @rack_context.stub(:getResourcePaths).and_return java.util.HashSet.new
- @rack_context.should_receive(:getResourcePaths).with('/WEB-INF/').and_return(
- java.util.HashSet.new(%w(app/ config/ lib/ vendor/).map{|f| "/WEB-INF/#{f}"}))
- @rack_context.should_receive(:getResourcePaths).with('/WEB-INF/lib/').and_return(
+ allow(@rack_context).to receive(:getResourcePaths).and_return java.util.HashSet.new
+ expect(@rack_context).to receive(:getResourcePaths).with('/WEB-INF/').and_return(
+ java.util.HashSet.new(%w(app/ config/ lib/ vendor/).map { |f| "/WEB-INF/#{f}" }))
+ expect(@rack_context).to receive(:getResourcePaths).with('/WEB-INF/lib/').and_return(
java.util.HashSet.new(["/WEB-INF/lib/config.ru"]))
- @rack_context.should_receive(:getResourceAsStream).with('/WEB-INF/lib/config.ru').
+ expect(@rack_context).to receive(:getResourceAsStream).with('/WEB-INF/lib/config.ru').
and_return StubInputStream.new("run MyRackApp")
@app_factory.init @rack_context
- @app_factory.rackup_script.should == 'run MyRackApp'
+ expect(@app_factory.rackup_script).to eq 'run MyRackApp'
end
it "should handle config.ru files with a coding: pragma" do
- @rack_config.should_receive(:getRackupPath).and_return '/WEB-INF/hello.ru'
- @rack_context.should_receive(:getResourceAsStream).with('/WEB-INF/hello.ru').
+ expect(@rack_config).to receive(:getRackupPath).and_return '/WEB-INF/hello.ru'
+ expect(@rack_context).to receive(:getResourceAsStream).with('/WEB-INF/hello.ru').
and_return StubInputStream.new("# coding: us-ascii\nrun MyRackApp")
@app_factory.init @rack_context
- @app_factory.rackup_script.should == "# coding: us-ascii\nrun MyRackApp"
+ expect(@app_factory.rackup_script).to eq "# coding: us-ascii\nrun MyRackApp"
end
it "initializes default request memory buffer size" do
- @rack_config.should_receive(:getInitialMemoryBufferSize).and_return 42
- @rack_config.should_receive(:getMaximumMemoryBufferSize).and_return 420
+ expect(@rack_config).to receive(:getInitialMemoryBufferSize).and_return 42
+ expect(@rack_config).to receive(:getMaximumMemoryBufferSize).and_return 420
@app_factory.init @rack_context
a_stream = java.io.ByteArrayInputStream.new(''.to_java_bytes)
input_stream = org.jruby.rack.servlet.RewindableInputStream.new(a_stream)
- input_stream.getCurrentBufferSize.should == 42
- input_stream.getMaximumBufferSize.should == 420
+ expect(input_stream.getCurrentBufferSize).to eq 42
+ expect(input_stream.getMaximumBufferSize).to eq 420
end
before do
@@ -170,30 +170,32 @@ def it_should_rewind_body
$servlet_context = @servlet_context
# NOTE: a workaround to be able to mock it :
klass = Class.new(DefaultRackApplicationFactory) do
- def createRackServletWrapper(runtime, rackup, filename); end
+ def createRackServletWrapper(runtime, rackup, filename)
+ ;
+ end
end
@app_factory = klass.new
- @rack_context.should_receive(:getRealPath).with('/config.ru').and_return nil
- #@rack_context.should_receive(:getContextPath).and_return '/'
- @rack_config.should_receive(:getRackup).and_return nil
- @rack_config.should_receive(:getRackupPath).and_return nil
+ expect(@rack_context).to receive(:getRealPath).with('/config.ru').and_return nil
+ # expect(@rack_context).to receive(:getContextPath).and_return '/'
+ expect(@rack_config).to receive(:getRackup).and_return nil
+ expect(@rack_config).to receive(:getRackupPath).and_return nil
@app_factory.init @rack_context
- @app_factory.rackup_script.should == nil
+ expect(@app_factory.rackup_script).to eq nil
- @rack_context.should_receive(:log) do |*args|
- expect( args.first.to_s ).to eql 'WARN' if args.size > 1
- args.last.should =~ /no rackup script found/
+ expect(@rack_context).to receive(:log) do |*args|
+ expect(args.first.to_s).to eql 'WARN' if args.size > 1
+ expect(args.last).to match(/no rackup script found/)
end
- @app_factory.should_receive(:createRackServletWrapper) do |runtime, rackup|
- runtime.should be JRuby.runtime
- rackup.should == ""
+ expect(@app_factory).to receive(:createRackServletWrapper) do |runtime, rackup|
+ expect(runtime).to be(JRuby.runtime)
+ expect(rackup).to eq ""
end
@app_factory.createApplicationObject(JRuby.runtime)
- JRuby::Rack.booter.should be_a(JRuby::Rack::Booter)
+ expect(JRuby::Rack.booter).to be_a(JRuby::Rack::Booter)
end
private
@@ -205,7 +207,8 @@ def reset_booter
def mocked_runtime_application_factory(factory_class = nil)
factory_class ||= org.jruby.rack.DefaultRackApplicationFactory
klass = Class.new(factory_class) do
- def newRuntime() # use the current runtime instead of creating new
+ def newRuntime()
+ # use the current runtime instead of creating new
require 'jruby'
runtime = JRuby.runtime
JRuby::Rack::Helpers.silence_warnings { initRuntime(runtime) }
@@ -218,12 +221,12 @@ def newRuntime() # use the current runtime instead of creating new
context "initialized" do
before :each do
- @rack_context.stub(:getInitParameter).and_return nil
- @rack_context.stub(:getResourcePaths).and_return nil
- @rack_context.stub(:getRealPath) { |path| path }
- #@rack_context.stub(:log) do |*args|
- #puts args.inspect
- #end
+ allow(@rack_context).to receive(:getInitParameter).and_return nil
+ allow(@rack_context).to receive(:getResourcePaths).and_return nil
+ allow(@rack_context).to receive(:getRealPath) { |path| path }
+ # allow(@rack_context).to receive(:log) do |*args|
+ # puts args.inspect
+ # end
end
let(:app_factory) do
@@ -234,26 +237,26 @@ def newRuntime() # use the current runtime instead of creating new
describe "error application" do
it "creates an error application (by default)" do
- app_factory.getErrorApplication.should respond_to(:call)
+ expect(app_factory.getErrorApplication).to respond_to(:call)
end
it "creates a Rack error application" do
error_application = app_factory.getErrorApplication
- expect( error_application ).to be_a(org.jruby.rack.ErrorApplication)
- expect( error_application ).to be_a(org.jruby.rack.DefaultRackApplication)
+ expect(error_application).to be_a(org.jruby.rack.ErrorApplication)
+ expect(error_application).to be_a(org.jruby.rack.DefaultRackApplication)
# NOTE: these get created in a new Ruby runtime :
rack_app = error_application.getApplication
- #expect( rack_app ).to be_a Rack::Handler::Servlet
- expect( rack_app.class.name ).to eql 'Rack::Handler::Servlet'
- expect( rack_app.app ).to be_a JRuby::Rack::ErrorApp::ShowStatus
- #expect( app.class.name ).to eql 'JRuby::Rack::ErrorApp::ShowStatus'
+ # expect(rack_app).to be_a Rack::Handler::Servlet
+ expect(rack_app.class.name).to eql 'Rack::Handler::Servlet'
+ expect(rack_app.app).to be_a JRuby::Rack::ErrorApp::ShowStatus
+ # expect(app.class.name).to eql 'JRuby::Rack::ErrorApp::ShowStatus'
error_app = rack_app.app.instance_variable_get('@app')
- expect( error_app ).to be_a JRuby::Rack::ErrorApp
- #expect( error_app.class.name ).to eql 'JRuby::Rack::ErrorApp'
+ expect(error_app).to be_a JRuby::Rack::ErrorApp
+ # expect(error_app.class.name).to eql 'JRuby::Rack::ErrorApp'
end
it "rackups a configured error application" do
- @rack_config.stub(:getProperty) do |name|
+ allow(@rack_config).to receive(:getProperty) do |name|
if name == 'jruby.rack.error.app'
"run Proc.new { 'error.app' }"
else
@@ -261,30 +264,30 @@ def newRuntime() # use the current runtime instead of creating new
end
end
error_application = app_factory.getErrorApplication
- expect( error_application ).to be_a(org.jruby.rack.ErrorApplication)
- expect( error_application ).to be_a(org.jruby.rack.DefaultRackApplication)
+ expect(error_application).to be_a(org.jruby.rack.ErrorApplication)
+ expect(error_application).to be_a(org.jruby.rack.DefaultRackApplication)
rack_app = error_application.getApplication
- expect( rack_app ).to be_a Rack::Handler::Servlet
- #expect( rack_app.class.name ).to eql 'Rack::Handler::Servlet'
- expect( app = rack_app.get_app ).to be_a Proc
- #expect( app.class.name ).to eql 'Proc'
- expect( app.call ).to eql 'error.app'
+ expect(rack_app).to be_a Rack::Handler::Servlet
+ # expect(rack_app.class.name).to eql 'Rack::Handler::Servlet'
+ expect(app = rack_app.get_app).to be_a Proc
+ # expect(app.class.name).to eql 'Proc'
+ expect(app.call).to eql 'error.app'
end
it "creates a 'default' error application as a fallback" do
- @rack_config.stub(:getProperty) do |name|
+ allow(@rack_config).to receive(:getProperty) do |name|
name == 'jruby.rack.error.app' ? "run MissingConstantApp" : nil
end
error_application = app_factory.getErrorApplication
- expect( error_application ).to be_a(org.jruby.rack.ErrorApplication)
+ expect(error_application).to be_a(org.jruby.rack.ErrorApplication)
rack_env = double("rack env")
- rack_env.should_receive(:getAttribute).with('jruby.rack.exception').
+ expect(rack_env).to receive(:getAttribute).with('jruby.rack.exception').
at_least(:once).and_return java.lang.RuntimeException.new('42')
response = error_application.call rack_env
- expect( response.getStatus ).to eql 500
- expect( response.getHeaders ).to be_empty
- expect( response.getBody ).to_not be nil
+ expect(response.getStatus).to eql 500
+ expect(response.getHeaders).to be_empty
+ expect(response.getBody).to_not be nil
end
end
@@ -293,7 +296,7 @@ def newRuntime() # use the current runtime instead of creating new
let(:app_factory) do
@rack_config = org.jruby.rack.DefaultRackConfig.new
- @rack_context.stub(:getConfig).and_return @rack_config
+ allow(@rack_context).to receive(:getConfig).and_return @rack_config
app_factory = org.jruby.rack.DefaultRackApplicationFactory.new
app_factory.init(@rack_context); app_factory
end
@@ -315,8 +318,8 @@ def newRuntime() # use the current runtime instead of creating new
set_config 'jruby.runtime.env', 'false'
script = "# encoding: UTF-8\n" +
- "# rack.version: bundler \n" +
- "Proc.new { 'proc-rack-app' }"
+ "# rack.version: bundler \n" +
+ "Proc.new { 'proc-rack-app' }"
app_factory.setRackupScript script
@runtime = app_factory.newRuntime
@@ -341,7 +344,7 @@ def newRuntime() # use the current runtime instead of creating new
end
it "clears environment variables if the configuration ignores the environment" do
- expect( ENV['HOME'] ).to_not eql ""
+ expect(ENV['HOME']).to_not eql ""
set_config 'jruby.runtime.env', ''
@runtime = app_factory.newRuntime
@@ -350,7 +353,7 @@ def newRuntime() # use the current runtime instead of creating new
end
it "sets ENV['PATH'] to an empty string if the configuration ignores the environment" do
- expect( ENV['PATH'] ).to_not be_empty
+ expect(ENV['PATH']).to_not be_empty
set_config 'jruby.runtime.env', 'false'
@runtime = app_factory.newRuntime
@@ -380,7 +383,7 @@ def newRuntime() # use the current runtime instead of creating new
it "does a complete ENV clean including RUBYOPT" do
set_config 'jruby.runtime.env', 'false'
- #set_config 'jruby.runtime.env.rubyopt', 'false'
+ # set_config 'jruby.runtime.env.rubyopt', 'false'
app_factory = app_factory_with_RUBYOPT '-ryaml'
@runtime = app_factory.newRuntime
@@ -392,25 +395,23 @@ def newRuntime() # use the current runtime instead of creating new
it "handles jruby.runtime.arguments == '-X+O -Ke' and start with object space enabled and KCode EUC" do
set_config 'jruby.runtime.arguments', '-X+O -Ke'
- #@rack_config.stub(:getRuntimeArguments).and_return ['-X+O', '-Ke'].to_java(:String)
+ # allow(@rack_config).to receive(:getRuntimeArguments).and_return ['-X+O', '-Ke'].to_java(:String)
@runtime = app_factory.new_runtime
- @runtime.object_space_enabled.should be_truthy
- @runtime.kcode.should == Java::OrgJrubyUtil::KCode::EUC
+ expect(@runtime.object_space_enabled).to be_truthy
+ expect(@runtime.kcode).to eq Java::OrgJrubyUtil::KCode::EUC
end
it "does not propagate ENV changes to JVM (and indirectly to other JRuby VM instances)" do
runtime = app_factory.new_runtime
- java.lang.System.getenv['VAR1'].should be_nil
- #Nil returned from Ruby VM don't have the rspec decorations'
- nil.should {
- runtime.evalScriptlet("ENV['VAR1']").nil?
- }
+ expect(java.lang.System.getenv['VAR1']).to be_nil
+ # Nil returned from Ruby VM don't have the rspec decorations'
+ expect(runtime.evalScriptlet("ENV['VAR1']")).to be_nil
result = runtime.evalScriptlet("ENV['VAR1'] = 'VALUE1';")
- #String returned from Ruby VM don't have the rspec decorations'
- String.new(result).should == 'VALUE1'
- java.lang.System.getenv['VAR1'].should be_nil
+ # String returned from Ruby VM don't have the rspec decorations'
+ expect(String.new(result)).to eq 'VALUE1'
+ expect(java.lang.System.getenv['VAR1']).to be_nil
end
private
@@ -419,7 +420,9 @@ def app_factory_with_RUBYOPT(rubyopt)
app_factory =
Class.new(org.jruby.rack.DefaultRackApplicationFactory) do
- def initialize(rubyopt); super(); @rubyopt = rubyopt; end
+ def initialize(rubyopt)
+ ; super(); @rubyopt = rubyopt;
+ end
def initRuntimeConfig(config)
env = java.util.HashMap.new config.getEnvironment
@@ -430,7 +433,7 @@ def initRuntimeConfig(config)
end.new(rubyopt)
@rack_config = org.jruby.rack.DefaultRackConfig.new
- @rack_context.stub(:getConfig).and_return @rack_config
+ allow(@rack_context).to receive(:getConfig).and_return @rack_config
app_factory.init(@rack_context)
app_factory
end
@@ -464,19 +467,19 @@ def reset_config
describe "newApplication" do
before :each do
- @rack_context.stub(:getRealPath).and_return Dir::tmpdir
+ allow(@rack_context).to receive(:getRealPath).and_return Dir::tmpdir
end
it "creates a Ruby object from the script snippet given" do
- @rack_config.should_receive(:getRackup).and_return("require 'rack/lobster'; Rack::Lobster.new")
+ expect(@rack_config).to receive(:getRackup).and_return("require 'rack/lobster'; Rack::Lobster.new")
app_factory = mocked_runtime_application_factory
app_factory.init @rack_context
app_object = app_factory.newApplication
- app_object.respond_to?(:call).should == true
+ expect(app_object.respond_to?(:call)).to eq true
end
it "raises an exception if creation failed" do
- @rack_config.should_receive(:getRackup).and_return("raise 'something went wrong'")
+ expect(@rack_config).to receive(:getRackup).and_return("raise 'something went wrong'")
app_factory = mocked_runtime_application_factory
app_factory.init @rack_context
app_object = app_factory.newApplication
@@ -484,30 +487,30 @@ def reset_config
app_object.init
fail "expected to raise"
rescue => e
- expect( e.message ).to eql 'something went wrong'
+ expect(e.message).to eql 'something went wrong'
end
end
end
describe "getApplication" do
it "creates an application and initializes it" do
- @rack_config.should_receive(:getRackup).and_return("raise 'init was called'")
+ expect(@rack_config).to receive(:getRackup).and_return("raise 'init was called'")
app_factory = mocked_runtime_application_factory
app_factory.init @rack_context
begin
app_factory.getApplication
fail "expected to raise"
rescue => e
- expect( e.message ).to eql 'init was called'
+ expect(e.message).to eql 'init was called'
end
- #lambda { app_factory.getApplication }.should raise_error
+ # expect { app_factory.getApplication }.to raise_error
end
end
describe "finishedWithApplication" do
it "should call destroy on the application object" do
rack_app = double "application"
- rack_app.should_receive(:destroy)
+ expect(rack_app).to receive(:destroy)
@app_factory.finishedWithApplication rack_app
end
end
@@ -515,7 +518,7 @@ def reset_config
describe "destroy" do
it "should call destroy on the error application" do
rack_app = double "error app"
- rack_app.should_receive(:destroy)
+ expect(rack_app).to receive(:destroy)
@app_factory.setErrorApplication rack_app
@app_factory.destroy
end
@@ -538,25 +541,27 @@ def reset_config
it "should init and create application object" do
# NOTE: a workaround to be able to mock it :
klass = Class.new(RailsRackApplicationFactory) do
- def createRackServletWrapper(runtime, rackup, filename); end
+ def createRackServletWrapper(runtime, rackup, filename)
+ ;
+ end
end
@app_factory = klass.new
- @rack_context.should_receive(:getRealPath).with('/config.ru').and_return nil
- #@rack_context.should_receive(:getContextPath).and_return '/'
- @rack_config.should_receive(:getRackup).and_return nil
- @rack_config.should_receive(:getRackupPath).and_return nil
+ expect(@rack_context).to receive(:getRealPath).with('/config.ru').and_return nil
+ # expect(@rack_context).to receive(:getContextPath).and_return '/'
+ expect(@rack_config).to receive(:getRackup).and_return nil
+ expect(@rack_config).to receive(:getRackupPath).and_return nil
@app_factory.init @rack_context
- @app_factory.should_receive(:createRackServletWrapper) do |runtime, rackup|
- runtime.should be JRuby.runtime
- rackup.should == "run JRuby::Rack::RailsBooter.to_app"
+ expect(@app_factory).to receive(:createRackServletWrapper) do |runtime, rackup|
+ expect(runtime).to be(JRuby.runtime)
+ expect(rackup).to eq "run JRuby::Rack::RailsBooter.to_app"
end
- JRuby::Rack::RailsBooter.should_receive(:load_environment)
+ expect(JRuby::Rack::RailsBooter).to receive(:load_environment)
@app_factory.createApplicationObject(JRuby.runtime)
- JRuby::Rack.booter.should be_a(JRuby::Rack::RailsBooter)
+ expect(JRuby::Rack.booter).to be_a(JRuby::Rack::RailsBooter)
end
end
@@ -570,126 +575,126 @@ def createRackServletWrapper(runtime, rackup, filename); end
end
it "should initialize the delegate factory when initialized" do
- @factory.should_receive(:init).with(@rack_context)
+ expect(@factory).to receive(:init).with(@rack_context)
@pooling_factory.init(@rack_context)
end
it "should start out empty" do
- @pooling_factory.getApplicationPool.should be_empty
+ expect(@pooling_factory.getApplicationPool).to be_empty
end
it "should create a new application when empty" do
app = double "app"
- @factory.should_receive(:getApplication).and_return app
- @pooling_factory.getApplication.should == app
+ expect(@factory).to receive(:getApplication).and_return app
+ expect(@pooling_factory.getApplication).to eq app
end
it "should not add newly created application to pool" do
app = double "app"
- @factory.should_receive(:getApplication).and_return app
- @pooling_factory.getApplication.should == app
- @pooling_factory.getApplicationPool.to_a.should == []
+ expect(@factory).to receive(:getApplication).and_return app
+ expect(@pooling_factory.getApplication).to eq app
+ expect(@pooling_factory.getApplicationPool.to_a).to eq []
end
it "accepts an existing application and puts it back in the pool" do
app = double "app"
- @pooling_factory.getApplicationPool.to_a.should == []
+ expect(@pooling_factory.getApplicationPool.to_a).to eq []
@pooling_factory.finishedWithApplication app
- @pooling_factory.getApplicationPool.to_a.should == [ app ]
- @pooling_factory.getApplication.should == app
+ expect(@pooling_factory.getApplicationPool.to_a).to eq [app]
+ expect(@pooling_factory.getApplication).to eq app
end
it "calls destroy on all cached applications when destroyed" do
app1, app2 = double("app1"), double("app2")
@pooling_factory.finishedWithApplication app1
@pooling_factory.finishedWithApplication app2
- @factory.should_receive(:finishedWithApplication).with(app1) # app1.should_receive(:destroy)
- @factory.should_receive(:finishedWithApplication).with(app2) # app2.should_receive(:destroy)
- @factory.should_receive(:destroy)
+ expect(@factory).to receive(:finishedWithApplication).with(app1) # expect(app1).to receive(:destroy)
+ expect(@factory).to receive(:finishedWithApplication).with(app2) # expect(app2).to receive(:destroy)
+ expect(@factory).to receive(:destroy)
@pooling_factory.destroy
- @pooling_factory.getApplicationPool.to_a.should == [] # and empty application pool
+ expect(@pooling_factory.getApplicationPool.to_a).to eq [] # and empty application pool
end
it "creates applications during initialization according to the jruby.min.runtimes context parameter" do
- @factory.stub(:init)
- @factory.stub(:newApplication) do
+ allow(@factory).to receive(:init)
+ allow(@factory).to receive(:newApplication) do
app = double "app"
- app.should_receive(:init)
+ expect(app).to receive(:init)
app
end
- @rack_config.should_receive(:getInitialRuntimes).and_return 1
+ expect(@rack_config).to receive(:getInitialRuntimes).and_return 1
@pooling_factory.init(@rack_context)
- @pooling_factory.getApplicationPool.size.should == 1
+ expect(@pooling_factory.getApplicationPool.size).to eq 1
end
it "does not allow new applications beyond the maximum specified by the jruby.max.runtimes context parameter" do
- @factory.stub(:init)
- @rack_config.should_receive(:getMaximumRuntimes).and_return 1
+ allow(@factory).to receive(:init)
+ expect(@rack_config).to receive(:getMaximumRuntimes).and_return 1
@pooling_factory.init(@rack_context)
@pooling_factory.finishedWithApplication double("app1")
@pooling_factory.finishedWithApplication double("app2")
- @pooling_factory.getApplicationPool.size.should == 1
+ expect(@pooling_factory.getApplicationPool.size).to eq 1
end
it "does not add an application back into the pool if it already exists" do
- @factory.stub(:init)
- @rack_config.should_receive(:getMaximumRuntimes).and_return 4
+ allow(@factory).to receive(:init)
+ expect(@rack_config).to receive(:getMaximumRuntimes).and_return 4
@pooling_factory.init(@rack_context)
rack_application_1 = double("app1")
@pooling_factory.finishedWithApplication rack_application_1
@pooling_factory.finishedWithApplication rack_application_1
- @pooling_factory.getApplicationPool.size.should == 1
+ expect(@pooling_factory.getApplicationPool.size).to eq 1
end
it "forces the maximum size to be greater or equal to the initial size" do
- @factory.stub(:init)
- @factory.stub(:newApplication) do
+ allow(@factory).to receive(:init)
+ allow(@factory).to receive(:newApplication) do
app = double "app"
- app.should_receive(:init)
+ expect(app).to receive(:init)
app
end
- @rack_config.should_receive(:getInitialRuntimes).and_return 2
- @rack_config.should_receive(:getMaximumRuntimes).and_return 1
+ expect(@rack_config).to receive(:getInitialRuntimes).and_return 2
+ expect(@rack_config).to receive(:getMaximumRuntimes).and_return 1
@pooling_factory.init(@rack_context)
- @pooling_factory.getApplicationPool.size.should == 2
+ expect(@pooling_factory.getApplicationPool.size).to eq 2
@pooling_factory.finishedWithApplication double("app")
- @pooling_factory.getApplicationPool.size.should == 2
+ expect(@pooling_factory.getApplicationPool.size).to eq 2
end
it "retrieves the error application from the delegate factory" do
app = double("app")
- @factory.should_receive(:getErrorApplication).and_return app
- @pooling_factory.getErrorApplication.should == app
+ expect(@factory).to receive(:getErrorApplication).and_return app
+ expect(@pooling_factory.getErrorApplication).to eq app
end
it "waits till initial runtimes get initialized (with wait set to true)" do
- @factory.stub(:init)
- @factory.stub(:newApplication) do
+ allow(@factory).to receive(:init)
+ allow(@factory).to receive(:newApplication) do
app = double "app"
- app.stub(:init) do
+ allow(app).to receive(:init) do
sleep(0.10)
end
app
end
- @rack_config.stub(:getBooleanProperty).with("jruby.runtime.init.wait").and_return true
- @rack_config.should_receive(:getInitialRuntimes).and_return 4
- @rack_config.should_receive(:getMaximumRuntimes).and_return 8
+ allow(@rack_config).to receive(:getBooleanProperty).with("jruby.runtime.init.wait").and_return true
+ expect(@rack_config).to receive(:getInitialRuntimes).and_return 4
+ expect(@rack_config).to receive(:getMaximumRuntimes).and_return 8
@pooling_factory.init(@rack_context)
- @pooling_factory.getApplicationPool.size.should >= 4
+ expect(@pooling_factory.getApplicationPool.size).to be >= 4
end
it "throws an exception from getApplication when an app failed to initialize " +
"(even when only a single application initialization fails)" do
- @factory.stub(:init)
+ allow(@factory).to receive(:init)
app_count = java.util.concurrent.atomic.AtomicInteger.new(0)
- @factory.stub(:newApplication) do
+ allow(@factory).to receive(:newApplication) do
app = double "app"
- app.stub(:init) do
+ allow(app).to receive(:init) do
if app_count.addAndGet(1) == 2
raise org.jruby.rack.RackInitializationException.new('failed app init')
end
@@ -698,9 +703,9 @@ def createRackServletWrapper(runtime, rackup, filename); end
app
end
num_runtimes = 3
- @rack_config.stub(:getBooleanProperty).with("jruby.runtime.init.wait").and_return false
- @rack_config.should_receive(:getInitialRuntimes).and_return num_runtimes
- @rack_config.should_receive(:getMaximumRuntimes).and_return num_runtimes
+ allow(@rack_config).to receive(:getBooleanProperty).with("jruby.runtime.init.wait").and_return false
+ expect(@rack_config).to receive(:getInitialRuntimes).and_return num_runtimes
+ expect(@rack_config).to receive(:getMaximumRuntimes).and_return num_runtimes
begin
@pooling_factory.init(@rack_context)
@@ -723,130 +728,126 @@ def createRackServletWrapper(runtime, rackup, filename); end
end
it "wait until pool is filled when invoking getApplication (with wait set to false)" do
- @factory.stub(:init)
- @factory.stub(:newApplication) do
+ allow(@factory).to receive(:init)
+ allow(@factory).to receive(:newApplication) do
app = double "app"
- app.stub(:init) { sleep(0.2) }
+ allow(app).to receive(:init) { sleep(0.2) }
app
end
- @rack_config.stub(:getBooleanProperty).with("jruby.runtime.init.wait").and_return false
- @rack_config.should_receive(:getInitialRuntimes).and_return 3
- @rack_config.should_receive(:getMaximumRuntimes).and_return 4
+ allow(@rack_config).to receive(:getBooleanProperty).with("jruby.runtime.init.wait").and_return false
+ expect(@rack_config).to receive(:getInitialRuntimes).and_return 3
+ expect(@rack_config).to receive(:getMaximumRuntimes).and_return 4
@pooling_factory.init(@rack_context)
millis = java.lang.System.currentTimeMillis
- @pooling_factory.getApplication.should_not be nil
+ expect(@pooling_factory.getApplication).not_to be nil
millis = java.lang.System.currentTimeMillis - millis
- millis.should >= 150 # getApplication waited ~ 0.2 secs
+ expect(millis).to be >= 150 # getApplication waited ~ 0.2 secs
end
it "waits acquire timeout till an application is available from the pool (than raises)" do
- @factory.stub(:init)
- @factory.should_receive(:newApplication).twice do
+ allow(@factory).to receive(:init)
+ expect(@factory).to receive(:newApplication).twice do
app = double "app"
- app.should_receive(:init) { sleep(0.2) }
+ expect(app).to receive(:init) { sleep(0.2) }
app
end
- @rack_config.stub(:getBooleanProperty).with("jruby.runtime.init.wait").and_return false
- @rack_config.should_receive(:getInitialRuntimes).and_return 2
- @rack_config.should_receive(:getMaximumRuntimes).and_return 2
+ allow(@rack_config).to receive(:getBooleanProperty).with("jruby.runtime.init.wait").and_return false
+ expect(@rack_config).to receive(:getInitialRuntimes).and_return 2
+ expect(@rack_config).to receive(:getMaximumRuntimes).and_return 2
@pooling_factory.init(@rack_context)
@pooling_factory.acquire_timeout = 1.to_java # second
millis = java.lang.System.currentTimeMillis
- @pooling_factory.getApplication.should_not be nil
+ expect(@pooling_factory.getApplication).not_to be nil
millis = java.lang.System.currentTimeMillis - millis
- millis.should >= 150 # getApplication waited ~ 0.2 secs
+ expect(millis).to be >= 150 # getApplication waited ~ 0.2 secs
app2 = @pooling_factory.getApplication # now the pool is empty
@pooling_factory.acquire_timeout = 0.1.to_java # second
millis = java.lang.System.currentTimeMillis
- lambda { @pooling_factory.getApplication }.should raise_error(org.jruby.rack.AcquireTimeoutException)
+ expect { @pooling_factory.getApplication }.to raise_error(org.jruby.rack.AcquireTimeoutException)
millis = java.lang.System.currentTimeMillis - millis
- millis.should >= 90 # waited about ~ 0.1 secs
+ expect(millis).to be >= 90 # waited about ~ 0.1 secs
@pooling_factory.finishedWithApplication(app2) # gets back to the pool
- lambda { @pooling_factory.getApplication.should == app2 }.should_not raise_error
+ expect(@pooling_factory.getApplication).to eq app2
end
it "gets and initializes new applications until maximum allows to create more" do
- @factory.stub(:init)
- @factory.should_receive(:newApplication).twice do
+ allow(@factory).to receive(:init)
+ expect(@factory).to receive(:newApplication).twice do
app = double "app (new)"
- app.should_receive(:init) { sleep(0.1) }
+ expect(app).to receive(:init) { sleep(0.1) }
app
end
- @rack_config.stub(:getBooleanProperty).with("jruby.runtime.init.wait").and_return false
- @rack_config.stub(:getInitialRuntimes).and_return 2
- @rack_config.stub(:getMaximumRuntimes).and_return 4
+ allow(@rack_config).to receive(:getBooleanProperty).with("jruby.runtime.init.wait").and_return false
+ allow(@rack_config).to receive(:getInitialRuntimes).and_return 2
+ allow(@rack_config).to receive(:getMaximumRuntimes).and_return 4
@pooling_factory.init(@rack_context)
@pooling_factory.acquire_timeout = 0.10.to_java # second
- lambda {
- 2.times { @pooling_factory.getApplication.should_not be nil }
- }.should_not raise_error
+ 2.times { expect(@pooling_factory.getApplication).not_to be nil }
- @factory.should_receive(:getApplication).twice do
+ expect(@factory).to receive(:getApplication).twice do
app = double "app (get)"; sleep(0.15); app
end
millis = java.lang.System.currentTimeMillis
- lambda {
- 2.times { @pooling_factory.getApplication.should_not be nil }
- }.should_not raise_error
+ 2.times { expect(@pooling_factory.getApplication).not_to be nil }
millis = java.lang.System.currentTimeMillis - millis
- millis.should >= 300 # waited about 2 x 0.15 secs
+ expect(millis).to be >= 300 # waited about 2 x 0.15 secs
millis = java.lang.System.currentTimeMillis
- lambda {
+ expect {
@pooling_factory.getApplication
- }.should raise_error(org.jruby.rack.AcquireTimeoutException)
+ }.to raise_error(org.jruby.rack.AcquireTimeoutException)
millis = java.lang.System.currentTimeMillis - millis
- millis.should >= 90 # waited about ~ 0.10 secs
+ expect(millis).to be >= 90 # waited about ~ 0.10 secs
end
it "initializes initial runtimes in paralel (with wait set to false)" do
- @factory.stub(:init)
- @factory.stub(:newApplication) do
+ allow(@factory).to receive(:init)
+ allow(@factory).to receive(:newApplication) do
app = double "app"
- app.stub(:init) do
+ allow(app).to receive(:init) do
sleep(0.15)
end
app
end
- @rack_config.stub(:getBooleanProperty).with("jruby.runtime.init.wait").and_return false
- @rack_config.stub(:getInitialRuntimes).and_return 6
- @rack_config.stub(:getMaximumRuntimes).and_return 8
+ allow(@rack_config).to receive(:getBooleanProperty).with("jruby.runtime.init.wait").and_return false
+ allow(@rack_config).to receive(:getInitialRuntimes).and_return 6
+ allow(@rack_config).to receive(:getMaximumRuntimes).and_return 8
@pooling_factory.init(@rack_context)
sleep(0.10)
- @pooling_factory.getApplicationPool.size.should < 6
+ expect(@pooling_factory.getApplicationPool.size).to be < 6
sleep(0.9)
- @pooling_factory.getApplicationPool.size.should >= 6
+ expect(@pooling_factory.getApplicationPool.size).to be >= 6
- expect( @pooling_factory.getManagedApplications ).to_not be_empty
- expect( @pooling_factory.getManagedApplications.size ).to eql 6
+ expect(@pooling_factory.getManagedApplications).to_not be_empty
+ expect(@pooling_factory.getManagedApplications.size).to eql 6
end
it "throws from init when application initialization in thread failed" do
- @factory.stub(:init)
- @factory.stub(:newApplication) do
+ allow(@factory).to receive(:init)
+ allow(@factory).to receive(:newApplication) do
app = double "app"
- app.stub(:init) do
+ allow(app).to receive(:init) do
sleep(0.05); raise "app.init raising"
end
app
end
- @rack_config.stub(:getInitialRuntimes).and_return 2
- @rack_config.stub(:getMaximumRuntimes).and_return 2
+ allow(@rack_config).to receive(:getInitialRuntimes).and_return 2
+ allow(@rack_config).to receive(:getMaximumRuntimes).and_return 2
raise_error_logged = 0
- @rack_context.stub(:log) do |level, msg, e|
+ allow(@rack_context).to receive(:log) do |level, msg, e|
if level.to_s == 'ERROR'
- expect( msg ).to eql 'unable to initialize application'
- expect( e ).to be_a org.jruby.exceptions.RaiseException
+ expect(msg).to eql 'unable to initialize application'
+ expect(e).to be_a org.jruby.exceptions.RaiseException
raise_error_logged += 1
else
true
@@ -854,10 +855,10 @@ def createRackServletWrapper(runtime, rackup, filename); end
end
expect { @pooling_factory.init(@rack_context) }.to raise_error org.jruby.rack.RackInitializationException
- expect( raise_error_logged ).to eql 1 # logs same init exception once
+ expect(raise_error_logged).to eql 1 # logs same init exception once
# NOTE: seems it's not such a good idea to return empty on init error
- # expect( @pooling_factory.getManagedApplications ).to be_empty
+ # expect(@pooling_factory.getManagedApplications).to be_empty
end
end
@@ -871,19 +872,19 @@ def createRackServletWrapper(runtime, rackup, filename); end
end
it "initializes initial runtimes in serial order" do
- @factory.should_receive(:init).with(@rack_context)
- @factory.stub(:newApplication) do
+ expect(@factory).to receive(:init).with(@rack_context)
+ allow(@factory).to receive(:newApplication) do
app = double "app"
- app.stub(:init) do
+ allow(app).to receive(:init) do
sleep(0.05)
end
app
end
- @rack_config.should_receive(:getInitialRuntimes).and_return 6
- @rack_config.should_receive(:getMaximumRuntimes).and_return 8
+ expect(@rack_config).to receive(:getInitialRuntimes).and_return 6
+ expect(@rack_config).to receive(:getMaximumRuntimes).and_return 8
@pooling_factory.init(@rack_context)
- @pooling_factory.getApplicationPool.size.should == 6
+ expect(@pooling_factory.getApplicationPool.size).to eq 6
end
end
@@ -896,22 +897,22 @@ def createRackServletWrapper(runtime, rackup, filename); end
end
it "initializes the delegate factory and creates the (shared) application when initialized" do
- @factory.should_receive(:init).with(@rack_context)
- @factory.should_receive(:getApplication).and_return app = double("application")
+ expect(@factory).to receive(:init).with(@rack_context)
+ expect(@factory).to receive(:getApplication).and_return app = double("application")
@shared_factory.init(@rack_context)
- expect( @shared_factory.getManagedApplications ).to_not be_empty
- expect( @shared_factory.getManagedApplications.size ).to eql 1
- expect( @shared_factory.getManagedApplications.to_a[0] ).to be app
+ expect(@shared_factory.getManagedApplications).to_not be_empty
+ expect(@shared_factory.getManagedApplications.size).to eql 1
+ expect(@shared_factory.getManagedApplications.to_a[0]).to be app
end
it "throws an exception if the shared application cannot be initialized " do
- @factory.should_receive(:init).with(@rack_context)
- @factory.should_receive(:getApplication).and_raise java.lang.ArithmeticException.new('42')
+ expect(@factory).to receive(:init).with(@rack_context)
+ expect(@factory).to receive(:getApplication).and_raise java.lang.ArithmeticException.new('42')
- @rack_context.should_receive(:log) do |level, msg, e|
+ expect(@rack_context).to receive(:log) do |level, msg, e|
if level == 'ERROR'
- expect( e ).to be_a java.lang.ArithmeticException
+ expect(e).to be_a java.lang.ArithmeticException
else
true
end
@@ -920,18 +921,18 @@ def createRackServletWrapper(runtime, rackup, filename); end
begin
@shared_factory.init(@rack_context)
rescue org.jruby.rack.RackInitializationException => e
- expect( e.message ).to eql 'java.lang.ArithmeticException: 42'
+ expect(e.message).to eql 'java.lang.ArithmeticException: 42'
else
fail "expected to rescue RackInitializationException"
end
- expect( @shared_factory.getManagedApplications ).to be nil
+ expect(@shared_factory.getManagedApplications).to be nil
end
it "throws initialization exception on each getApplication call if init failed" do
- @factory.should_receive(:init).with(@rack_context)
- @factory.should_receive(:getApplication).and_raise java.lang.RuntimeException.new('42')
- @factory.should_not_receive(:getErrorApplication) # dispacther invokes this ...
+ expect(@factory).to receive(:init).with(@rack_context)
+ expect(@factory).to receive(:getApplication).and_raise java.lang.RuntimeException.new('42')
+ expect(@factory).not_to receive(:getErrorApplication) # dispacther invokes this ...
begin
@shared_factory.init(@rack_context)
@@ -942,28 +943,28 @@ def createRackServletWrapper(runtime, rackup, filename); end
end
it "returns the same application for any newApplication or getApplication call" do
- @factory.should_receive(:init).with(@rack_context)
- @factory.should_receive(:getApplication).and_return app = double("application")
+ expect(@factory).to receive(:init).with(@rack_context)
+ expect(@factory).to receive(:getApplication).and_return app = double("application")
@shared_factory.init(@rack_context)
1.upto(5) do
- @shared_factory.newApplication.should == app
- @shared_factory.getApplication.should == app
+ expect(@shared_factory.newApplication).to eq app
+ expect(@shared_factory.getApplication).to eq app
@shared_factory.finishedWithApplication app
end
end
it "finished with application using delegate factory when destroyed" do
- @factory.should_receive(:init).with(@rack_context)
- @factory.should_receive(:getApplication).and_return app = double("application")
- @factory.should_receive(:destroy)
- @factory.should_receive(:finishedWithApplication).with(app)
+ expect(@factory).to receive(:init).with(@rack_context)
+ expect(@factory).to receive(:getApplication).and_return app = double("application")
+ expect(@factory).to receive(:destroy)
+ expect(@factory).to receive(:finishedWithApplication).with(app)
@shared_factory.init(@rack_context)
@shared_factory.destroy
end
it "retrieves the error application from the delegate factory" do
- @factory.should_receive(:getErrorApplication).and_return app = double("error app")
- @shared_factory.getErrorApplication.should == app
+ expect(@factory).to receive(:getErrorApplication).and_return app = double("error app")
+ expect(@shared_factory.getErrorApplication).to eq app
end
end
\ No newline at end of file
diff --git a/src/spec/ruby/rack/capture_spec.rb b/src/spec/ruby/rack/capture_spec.rb
index ef6990287..995c10642 100644
--- a/src/spec/ruby/rack/capture_spec.rb
+++ b/src/spec/ruby/rack/capture_spec.rb
@@ -13,15 +13,15 @@
before :each do
JRuby::Rack.context = nil
$servlet_context = @servlet_context
- @servlet_context.stub(:init_parameter_names).and_return []
+ allow(@servlet_context).to receive(:init_parameter_names).and_return []
end
it "captures environment information" do
- @servlet_context.should_receive(:log)
+ expect(@servlet_context).to receive(:log)
error = StandardError.new
error.capture
error.store
- expect( error.output ).to be_a StringIO
+ expect(error.output).to be_a StringIO
end
it "captures exception backtrace" do
@@ -29,8 +29,8 @@
raise ZeroDivisionError.new
rescue ZeroDivisionError => e
e.capture
- expect( e.output.string ).to match /--- Backtrace/
- expect( e.output.string ).to match /ZeroDivisionError/
+ expect(e.output.string).to match /--- Backtrace/
+ expect(e.output.string).to match /ZeroDivisionError/
end
end
diff --git a/src/spec/ruby/rack/config_spec.rb b/src/spec/ruby/rack/config_spec.rb
index 1d809f10c..45b136950 100644
--- a/src/spec/ruby/rack/config_spec.rb
+++ b/src/spec/ruby/rack/config_spec.rb
@@ -11,12 +11,12 @@
it "constructs a standard out logger when the logging attribute is unrecognized" do
java.lang.System.setProperty("jruby.rack.logging", "other")
- logger.should be_a(org.jruby.rack.logging.StandardOutLogger)
+ expect(logger).to be_a(org.jruby.rack.logging.StandardOutLogger)
end
it "constructs a standard out logger when the logger can't be instantiated" do
java.lang.System.setProperty("jruby.rack.logging", "java.lang.String")
- logger.should be_a(org.jruby.rack.logging.StandardOutLogger)
+ expect(logger).to be_a(org.jruby.rack.logging.StandardOutLogger)
end
after { java.lang.System.clearProperty("jruby.rack.logging") }
@@ -37,144 +37,144 @@
after { java.lang.System.clearProperty("jruby.rack.logging") }
it "constructs a slf4j logger from the context init param" do
- @servlet_context.should_receive(:getInitParameter).with("jruby.rack.logging").and_return "slf4j"
- logger.should be_a(org.jruby.rack.logging.Slf4jLogger)
+ expect(@servlet_context).to receive(:getInitParameter).with("jruby.rack.logging").and_return "slf4j"
+ expect(logger).to be_a(org.jruby.rack.logging.Slf4jLogger)
end
it "constructs a log4j logger from the context init param" do
- @servlet_context.should_receive(:getInitParameter).with("jruby.rack.logging").and_return "log4j"
- logger.should be_a(org.jruby.rack.logging.Log4jLogger)
+ expect(@servlet_context).to receive(:getInitParameter).with("jruby.rack.logging").and_return "log4j"
+ expect(logger).to be_a(org.jruby.rack.logging.Log4jLogger)
end
it "constructs a commons logging logger from system properties" do
java.lang.System.setProperty("jruby.rack.logging", "commons_logging")
- logger.should be_a(org.jruby.rack.logging.CommonsLoggingLogger)
+ expect(logger).to be_a(org.jruby.rack.logging.CommonsLoggingLogger)
end
it "constructs a jul logger with logger name" do
- @servlet_context.should_receive(:getInitParameter).with("jruby.rack.logging.name").and_return "/myapp"
- @servlet_context.should_receive(:getInitParameter).with("jruby.rack.logging").and_return "JUL"
- logger.should be_a(org.jruby.rack.logging.JulLogger)
- logger.getLogger.name.should == '/myapp'
+ expect(@servlet_context).to receive(:getInitParameter).with("jruby.rack.logging.name").and_return "/myapp"
+ expect(@servlet_context).to receive(:getInitParameter).with("jruby.rack.logging").and_return "JUL"
+ expect(logger).to be_a(org.jruby.rack.logging.JulLogger)
+ expect(logger.getLogger.name).to eq '/myapp'
end
it "constructs a slf4j logger with default logger name" do
java.lang.System.setProperty("jruby.rack.logging", "slf4j")
- logger.should be_a(org.jruby.rack.logging.Slf4jLogger)
- logger.getLogger.name.should == 'jruby.rack'
+ expect(logger).to be_a(org.jruby.rack.logging.Slf4jLogger)
+ expect(logger.getLogger.name).to eq 'jruby.rack'
end
it "constructs a log4j logger with default logger name" do
java.lang.System.setProperty("jruby.rack.logging", "log4j")
- logger.should be_a(org.jruby.rack.logging.Log4jLogger)
- logger.getLogger.name.should == 'jruby.rack'
+ expect(logger).to be_a(org.jruby.rack.logging.Log4jLogger)
+ expect(logger.getLogger.name).to eq 'jruby.rack'
end
it "constructs a logger from the context init params over system properties" do
- @servlet_context.should_receive(:getInitParameter).with("jruby.rack.logging").and_return "clogging"
+ expect(@servlet_context).to receive(:getInitParameter).with("jruby.rack.logging").and_return "clogging"
java.lang.System.setProperty("jruby.rack.logging", "stdout")
- logger.should be_a(org.jruby.rack.logging.CommonsLoggingLogger)
+ expect(logger).to be_a(org.jruby.rack.logging.CommonsLoggingLogger)
end
it "constructs a servlet logger when the logging attribute is unrecognized" do
java.lang.System.setProperty("jruby.rack.logging", "other")
- logger.should be_a(org.jruby.rack.logging.ServletContextLogger)
+ expect(logger).to be_a(org.jruby.rack.logging.ServletContextLogger)
end
it "constructs a servlet logger when the logger can't be instantiated" do
java.lang.System.setProperty("jruby.rack.logging", "java.lang.String")
- logger.should be_a(org.jruby.rack.logging.ServletContextLogger)
+ expect(logger).to be_a(org.jruby.rack.logging.ServletContextLogger)
end
it "constructs a servlet context logger by default" do
- logger.should be_a(org.jruby.rack.logging.ServletContextLogger)
+ expect(logger).to be_a(org.jruby.rack.logging.ServletContextLogger)
end
it "allows specifying a class name in the logging attribute" do
java.lang.System.setProperty("jruby.rack.logging", "org.jruby.rack.logging.CommonsLoggingLogger")
- logger.should be_a(org.jruby.rack.logging.CommonsLoggingLogger)
+ expect(logger).to be_a(org.jruby.rack.logging.CommonsLoggingLogger)
end
end
describe "runtime counts" do
it "should retrieve the minimum and maximum counts from jruby.min and jruby.max.runtimes" do
- @servlet_context.should_receive(:getInitParameter).with("jruby.min.runtimes").and_return "1"
- @servlet_context.should_receive(:getInitParameter).with("jruby.max.runtimes").and_return "2"
- config.initial_runtimes.should == 1
- config.maximum_runtimes.should == 2
+ expect(@servlet_context).to receive(:getInitParameter).with("jruby.min.runtimes").and_return "1"
+ expect(@servlet_context).to receive(:getInitParameter).with("jruby.max.runtimes").and_return "2"
+ expect(config.initial_runtimes).to eq 1
+ expect(config.maximum_runtimes).to eq 2
end
it "should recognize the jruby.pool.minIdle and jruby.pool.maxActive parameters from Goldspike" do
- @servlet_context.should_receive(:getInitParameter).with("jruby.pool.minIdle").and_return "1"
- @servlet_context.should_receive(:getInitParameter).with("jruby.pool.maxActive").and_return "2"
- config.initial_runtimes.should == 1
- config.maximum_runtimes.should == 2
+ expect(@servlet_context).to receive(:getInitParameter).with("jruby.pool.minIdle").and_return "1"
+ expect(@servlet_context).to receive(:getInitParameter).with("jruby.pool.maxActive").and_return "2"
+ expect(config.initial_runtimes).to eq 1
+ expect(config.maximum_runtimes).to eq 2
end
end
describe "runtime arguments" do
it "should retrieve single argument from jruby.runtime.arguments" do
- @servlet_context.should_receive(:getInitParameter).with("jruby.runtime.arguments").
+ expect(@servlet_context).to receive(:getInitParameter).with("jruby.runtime.arguments").
and_return nil
- config.runtime_arguments.should be_nil
+ expect(config.runtime_arguments).to be_nil
end
it "should retrieve single argument from jruby.runtime.arguments" do
- @servlet_context.should_receive(:getInitParameter).with("jruby.runtime.arguments").
+ expect(@servlet_context).to receive(:getInitParameter).with("jruby.runtime.arguments").
and_return "--profile"
args = config.runtime_arguments
- args.should_not be_nil
- args.length.should == 1
- args[0].should == "--profile"
+ expect(args).not_to be_nil
+ expect(args.length).to eq 1
+ expect(args[0]).to eq "--profile"
end
it "should retrieve multiple argument from jruby.runtime.arguments" do
- @servlet_context.should_receive(:getInitParameter).with("jruby.runtime.arguments").
+ expect(@servlet_context).to receive(:getInitParameter).with("jruby.runtime.arguments").
and_return " --compat RUBY1_8 \n --profile.api --debug \n\r"
args = config.runtime_arguments
- args.should_not be_nil
- args.length.should == 4
- args[0].should == "--compat"
- args[1].should == "RUBY1_8"
- args[2].should == "--profile.api"
- args[3].should == "--debug"
+ expect(args).not_to be_nil
+ expect(args.length).to eq 4
+ expect(args[0]).to eq "--compat"
+ expect(args[1]).to eq "RUBY1_8"
+ expect(args[2]).to eq "--profile.api"
+ expect(args[3]).to eq "--debug"
end
end
describe "runtime environment" do
it "defaults to nil (runtime should keep default from System env)" do
- @servlet_context.should_receive(:getInitParameter).
+ expect(@servlet_context).to receive(:getInitParameter).
with("jruby.runtime.environment").and_return nil
- expect( config.getRuntimeEnvironment ).to be nil
+ expect(config.getRuntimeEnvironment).to be nil
end
it "is empty when set to false" do
- @servlet_context.should_receive(:getInitParameter).
+ expect(@servlet_context).to receive(:getInitParameter).
with("jruby.runtime.environment").and_return 'false'
expect_empty_env config.getRuntimeEnvironment
end
it "setting jruby.rack.ignore.env returns empty env (backwards compat)" do
- @servlet_context.should_receive(:getInitParameter).
+ expect(@servlet_context).to receive(:getInitParameter).
with("jruby.rack.ignore.env").and_return 'true'
expect_empty_env config.getRuntimeEnvironment
end
it "custom env hash" do
- @servlet_context.should_receive(:getInitParameter).
+ expect(@servlet_context).to receive(:getInitParameter).
with("jruby.runtime.environment").
and_return "PATH=~/bin,HOME=/home/kares\nNAMES=Jozko, Ferko,Janko,GEM_HOME=/opt/rvm/gems\n"
- expect( config.getRuntimeEnvironment ).to eql({
- "PATH"=>"~/bin", "HOME"=>"/home/kares", "NAMES"=>"Jozko, Ferko,Janko", "GEM_HOME"=>"/opt/rvm/gems"
- })
+ expect(config.getRuntimeEnvironment).to eql({
+ "PATH" => "~/bin", "HOME" => "/home/kares", "NAMES" => "Jozko, Ferko,Janko", "GEM_HOME" => "/opt/rvm/gems"
+ })
end
private
def expect_empty_env(env)
- expect( env ).to_not be nil
- expect( env ).to be_empty
+ expect(env).to_not be nil
+ expect(env).to be_empty
# but mutable :
env.put 'PATH', '~/bin'
end
@@ -184,13 +184,13 @@ def expect_empty_env(env)
describe "rewindable" do
it "defaults to true" do
- expect( config ).to be_rewindable
+ expect(config).to be_rewindable
end
it "can be configured" do
- @servlet_context.should_receive(:getInitParameter).
+ expect(@servlet_context).to receive(:getInitParameter).
with("jruby.rack.input.rewindable").and_return "false"
- expect( config ).to_not be_rewindable
+ expect(config).to_not be_rewindable
end
end
@@ -198,33 +198,33 @@ def expect_empty_env(env)
describe "custom-properties" do
it "parser an int property" do
- @servlet_context.should_receive(:getInitParameter).with("jruby.some.timeout").and_return "1"
- expect( config.getNumberProperty('jruby.some.timeout') ).to eql 1
+ expect(@servlet_context).to receive(:getInitParameter).with("jruby.some.timeout").and_return "1"
+ expect(config.getNumberProperty('jruby.some.timeout')).to eql 1
end
it "returns a default value" do
- @servlet_context.should_receive(:getInitParameter).with("jruby.some.timeout").and_return nil
- expect( config.getNumberProperty('jruby.some.timeout', java.lang.Integer.new(10)) ).to eql 10
+ expect(@servlet_context).to receive(:getInitParameter).with("jruby.some.timeout").and_return nil
+ expect(config.getNumberProperty('jruby.some.timeout', java.lang.Integer.new(10))).to eql 10
end
it "parser a float property" do
- @servlet_context.should_receive(:getInitParameter).with("jruby.some.timeout").and_return "0.25"
- expect( config.getNumberProperty('jruby.some.timeout') ).to eql 0.25
+ expect(@servlet_context).to receive(:getInitParameter).with("jruby.some.timeout").and_return "0.25"
+ expect(config.getNumberProperty('jruby.some.timeout')).to eql 0.25
end
it "parser a big negative value" do
- @servlet_context.should_receive(:getInitParameter).with("jruby.some.timeout").and_return "-20000000000"
- expect( config.getNumberProperty('jruby.some.timeout') ).to eql -20000000000.0
+ expect(@servlet_context).to receive(:getInitParameter).with("jruby.some.timeout").and_return "-20000000000"
+ expect(config.getNumberProperty('jruby.some.timeout')).to eql -20000000000.0
end
it "parser a boolean flag" do
- @servlet_context.should_receive(:getInitParameter).with("jruby.some.flag").and_return "true"
- expect( config.getBooleanProperty('jruby.some.flag') ).to be true
+ expect(@servlet_context).to receive(:getInitParameter).with("jruby.some.flag").and_return "true"
+ expect(config.getBooleanProperty('jruby.some.flag')).to be true
end
it "parser a boolean (falsy) flag" do
- @servlet_context.should_receive(:getInitParameter).with("jruby.some.flag").and_return "F"
- expect( config.getBooleanProperty('jruby.some.flag') ).to be false
+ expect(@servlet_context).to receive(:getInitParameter).with("jruby.some.flag").and_return "F"
+ expect(config.getBooleanProperty('jruby.some.flag')).to be false
end
end
diff --git a/src/spec/ruby/rack/dispatcher_spec.rb b/src/spec/ruby/rack/dispatcher_spec.rb
index 05d63756a..55ec5d899 100644
--- a/src/spec/ruby/rack/dispatcher_spec.rb
+++ b/src/spec/ruby/rack/dispatcher_spec.rb
@@ -11,7 +11,7 @@
before :each do
@rack_factory = org.jruby.rack.RackApplicationFactory.impl {}
- @rack_context.should_receive(:getRackFactory).at_least(1).and_return @rack_factory
+ expect(@rack_context).to receive(:getRackFactory).at_least(1).and_return @rack_factory
@dispatcher = org.jruby.rack.DefaultRackDispatcher.new @rack_context
end
@@ -23,64 +23,64 @@
response = double("response")
rack_response = double("rack response")
- @rack_factory.should_receive(:getApplication).and_return(application)
- @rack_factory.should_receive(:finishedWithApplication).with(application)
- application.should_receive(:call).and_return rack_response
- rack_response.should_receive(:respond)
+ expect(@rack_factory).to receive(:getApplication).and_return(application)
+ expect(@rack_factory).to receive(:finishedWithApplication).with(application)
+ expect(application).to receive(:call).and_return rack_response
+ expect(rack_response).to receive(:respond)
@dispatcher.process(request, response)
end
it "stops processing on error if the response is already committed" do
application = double("application")
- @rack_factory.stub(:getApplication).and_return application
- @rack_factory.should_receive(:finishedWithApplication).with application
- application.stub(:call).and_raise "some error"
+ allow(@rack_factory).to receive(:getApplication).and_return application
+ expect(@rack_factory).to receive(:finishedWithApplication).with application
+ allow(application).to receive(:call).and_raise "some error"
req, res = double("request"), double("response")
- res.stub(:isCommitted).and_return true
+ allow(res).to receive(:isCommitted).and_return true
@dispatcher.process(req, res)
end
context 'init error' do
before do
- @rack_factory.stub(:getApplication).and_raise org.jruby.rack.RackInitializationException.new('fock')
- @rack_factory.stub(:getErrorApplication).and_return @error_app = double("error application")
+ allow(@rack_factory).to receive(:getApplication).and_raise org.jruby.rack.RackInitializationException.new('fock')
+ allow(@rack_factory).to receive(:getErrorApplication).and_return @error_app = double("error application")
end
it "lets the error application handle the error if the application could not be initialized" do
req, res = double("request"), double("response")
- req.should_receive(:setAttribute).with(org.jruby.rack.RackEnvironment::EXCEPTION, anything())
- res.should_receive(:isCommitted).and_return false
- res.should_receive(:reset)
+ expect(req).to receive(:setAttribute).with(org.jruby.rack.RackEnvironment::EXCEPTION, anything())
+ expect(res).to receive(:isCommitted).and_return false
+ expect(res).to receive(:reset)
rack_response = double "rack response"
- @error_app.should_receive(:call).and_return rack_response
- rack_response.should_receive(:respond)
+ expect(@error_app).to receive(:call).and_return rack_response
+ expect(rack_response).to receive(:respond)
@dispatcher.process(req, res)
end
it "sends a 500 error if the error application can't successfully handle the error" do
- @error_app.should_receive(:call).and_raise "some error"
+ expect(@error_app).to receive(:call).and_raise "some error"
req, res = double("request"), double("response")
- req.stub(:setAttribute)
- res.stub(:isCommitted).and_return false
- res.stub(:reset)
+ allow(req).to receive(:setAttribute)
+ allow(res).to receive(:isCommitted).and_return false
+ allow(res).to receive(:reset)
- res.should_receive(:sendError).with(500)
+ expect(res).to receive(:sendError).with(500)
@dispatcher.process(req, res)
end
it "allows the error app to re-throw a RackException" do
- @error_app.should_receive(:call) do
+ expect(@error_app).to receive(:call) do
raise org.jruby.rack.RackException.new('a rack exception')
end
req, res = double("request"), double("response")
- req.stub(:setAttribute)
- res.stub(:isCommitted).and_return false
- res.stub(:reset)
- res.should_not_receive(:sendError)
+ allow(req).to receive(:setAttribute)
+ allow(res).to receive(:isCommitted).and_return false
+ allow(res).to receive(:reset)
+ expect(res).not_to receive(:sendError)
expect { @dispatcher.process(req, res) }.to raise_error(org.jruby.rack.RackException)
end
diff --git a/src/spec/ruby/rack/embed/config_spec.rb b/src/spec/ruby/rack/embed/config_spec.rb
index 5a6a6b0db..586f7f94b 100644
--- a/src/spec/ruby/rack/embed/config_spec.rb
+++ b/src/spec/ruby/rack/embed/config_spec.rb
@@ -8,11 +8,11 @@
java.lang.System.set_property "truish", "true"
java.lang.System.set_property "falsish", "false"
- subject.get_property('foo').should == 'bar'
- subject.get_property('foo', 'BAR').should == 'bar'
+ expect(subject.get_property('foo')).to eq 'bar'
+ expect(subject.get_property('foo', 'BAR')).to eq 'bar'
- subject.get_boolean_property('truish').should == true
- subject.get_boolean_property('falsish', true).should == false
+ expect(subject.get_boolean_property('truish')).to eq true
+ expect(subject.get_boolean_property('falsish', true)).to eq false
ensure
java.lang.System.clear_property "foo"
java.lang.System.clear_property "truish"
@@ -20,31 +20,6 @@
end
end
-# it "honors properties from provided config if available" do
-# foo_config = org.jruby.rack.RackConfig.impl {}
-# def foo_config.getProperty(name, default = nil)
-# name == 'foo' ? 'bar' : default
-# end
-#
-# constructor = org.jruby.rack.embed.Config.java_class.to_java.
-# getDeclaredConstructor([ org.jruby.rack.RackConfig.java_class ].to_java :'java.lang.Class')
-# constructor.setAccessible(true)
-# config = constructor.newInstance(foo_config) # org.jruby.rack.embed.Config.new(foo_config)
-#
-# begin
-# java.lang.System.set_property "foo", "BAR"
-# java.lang.System.set_property "bar", "FOO"
-#
-# config.getProperty('some').should be nil
-#
-# config.getProperty('foo').should == 'bar'
-# config.getProperty('bar').should == 'FOO'
-# ensure
-# java.lang.System.clear_property "foo"
-# java.lang.System.clear_property "bar"
-# end
-# end
-
context "initialized" do
before(:each) do
@@ -58,11 +33,11 @@
ENV['env_true'] = 'true'
ENV['env_false'] = 'false'
- @config.get_property('env_foo').should == 'env_bar'
- @config.get_property('env_true').should == 'true'
+ expect(@config.get_property('env_foo')).to eq 'env_bar'
+ expect(@config.get_property('env_true')).to eq 'true'
- @config.get_boolean_property('env_true').should == true
- @config.get_boolean_property('env_false').should == false
+ expect(@config.get_boolean_property('env_true')).to eq true
+ expect(@config.get_boolean_property('env_false')).to eq false
ensure
ENV.delete('env_foo')
ENV.delete('env_true')
@@ -75,8 +50,8 @@
ENV["jruby.rack.request.size.initial.bytes"] = '1024'
ENV["jruby.rack.request.size.maximum.bytes"] = '4096'
- @config.getInitialMemoryBufferSize.should == 1024
- @config.getMaximumMemoryBufferSize.should == 4096
+ expect(@config.getInitialMemoryBufferSize).to eq 1024
+ expect(@config.getMaximumMemoryBufferSize).to eq 4096
ensure
ENV.delete("jruby.rack.request.size.initial.bytes")
ENV.delete("jruby.rack.request.size.treshold.bytes")
@@ -88,7 +63,7 @@
err = java.io.ByteArrayOutputStream.new
config = org.jruby.RubyInstanceConfig.new
config.output = java.io.PrintStream.new(out)
- config.error = java.io.PrintStream.new(err)
+ config.error = java.io.PrintStream.new(err)
@config.doInitialize org.jruby.Ruby.newInstance(config)
@config.getOut.println "hello out!"
diff --git a/src/spec/ruby/rack/embed/context_spec.rb b/src/spec/ruby/rack/embed/context_spec.rb
index ab7d1eb43..c0dc8c907 100644
--- a/src/spec/ruby/rack/embed/context_spec.rb
+++ b/src/spec/ruby/rack/embed/context_spec.rb
@@ -13,32 +13,35 @@
it "outputs log messages out to stdout" do
context.log "does this string appear?"
- captured["does this string appear?"].should_not be nil
+ expect(captured["does this string appear?"]).not_to be nil
end
it "outputs log messages with level and new line to stdout" do
info = org.jruby.rack.RackLogger::Level::INFO
context.log info, "this is logging at its best"
- captured.should == "INFO: this is logging at its best\n"
+ expect(captured).to eq "INFO: this is logging at its best\n"
end
it "outputs error log messages to stderr" do
- my_error = begin
- raise java.lang.RuntimeException.new "shizzle sticks"
- rescue java.lang.RuntimeException; $! ; end
+ my_error =
+ begin
+ raise java.lang.RuntimeException.new "shizzle sticks"
+ rescue java.lang.RuntimeException;
+ $!;
+ end
context.log("an error, gosh", my_error)
- captured["an error, gosh"].should_not be nil
- captured["shizzle sticks"].should_not be nil
- captured["RuntimeException"].should_not be nil
+ expect(captured["an error, gosh"]).not_to be nil
+ expect(captured["shizzle sticks"]).not_to be nil
+ expect(captured["RuntimeException"]).not_to be nil
end
context "with specific info" do
let(:server_info) { "awesome power server" }
it "returns the server info given to it as a constructor argument" do
- context.get_server_info.should == "awesome power server"
+ expect(context.get_server_info).to eq "awesome power server"
end
end
end
diff --git a/src/spec/ruby/rack/embed/dispatcher_spec.rb b/src/spec/ruby/rack/embed/dispatcher_spec.rb
index c89f19a8e..451b62cc1 100644
--- a/src/spec/ruby/rack/embed/dispatcher_spec.rb
+++ b/src/spec/ruby/rack/embed/dispatcher_spec.rb
@@ -9,7 +9,7 @@
it "initializes $servlet_context", :deprecated => true do
org.jruby.rack.embed.Dispatcher.new context, application
- $servlet_context.should be context
+ expect($servlet_context).to be(context)
end
it "initializes JRuby::Rack.context" do
@@ -17,7 +17,7 @@
JRuby::Rack.context = nil
begin
org.jruby.rack.embed.Dispatcher.new context, application
- expect( JRuby::Rack.context ).to be context
+ expect(JRuby::Rack.context).to be context
ensure
JRuby::Rack.context = prev_context
end
@@ -28,9 +28,9 @@
err = java.io.ByteArrayOutputStream.new
config = org.jruby.RubyInstanceConfig.new
config.output = java.io.PrintStream.new(out)
- config.error = java.io.PrintStream.new(err)
+ config.error = java.io.PrintStream.new(err)
runtime = org.jruby.Ruby.newInstance(config)
- application.stub(:getRuntime).and_return runtime
+ allow(application).to receive(:getRuntime).and_return runtime
$stdout = StringIO.new 'out'
$stderr = StringIO.new 'err'
@@ -39,8 +39,8 @@
runtime.evalScriptlet "$stdout.puts 'out from out there!'"
runtime.evalScriptlet "STDERR.puts 'error it is not ...'"
- expect(out.toString).to include "out from out there!\n"
- expect(err.toString).to include "error it is not ...\n"
+ expect(out.toString).to include "out from out there!\n"
+ expect(err.toString).to include "error it is not ...\n"
end
end
diff --git a/src/spec/ruby/rack/embed/filter_spec.rb b/src/spec/ruby/rack/embed/filter_spec.rb
index e2f8b95d0..a2d3ba09d 100644
--- a/src/spec/ruby/rack/embed/filter_spec.rb
+++ b/src/spec/ruby/rack/embed/filter_spec.rb
@@ -4,22 +4,22 @@
let(:rack_application) { double "rack application" }
let(:embed_rack_context) { org.jruby.rack.embed.Context.new "test server" }
- let(:dispatcher) { org.jruby.rack.embed.Dispatcher.new embed_rack_context, rack_application }
+ let(:dispatcher) { org.jruby.rack.embed.Dispatcher.new embed_rack_context, rack_application }
let(:filter) { org.jruby.rack.embed.Filter.new dispatcher, embed_rack_context }
let(:chain) { double "filter chain" }
let(:request) do
javax.servlet.http.HttpServletRequest.impl {}.tap do |request|
- request.stub(:getInputStream).and_return(StubServletInputStream.new)
+ allow(request).to receive(:getInputStream).and_return(StubServletInputStream.new)
end
end
let(:response) { javax.servlet.http.HttpServletResponse.impl {} }
it "serves all requests using the given rack application" do
rack_response = double "rack response"
- rack_response.should_receive(:respond)
- rack_application.should_receive(:call).and_return rack_response
+ expect(rack_response).to receive(:respond)
+ expect(rack_application).to receive(:call).and_return rack_response
filter.doFilter(request, response, chain)
end
diff --git a/src/spec/ruby/rack/filter_spec.rb b/src/spec/ruby/rack/filter_spec.rb
index e5a991094..a5b4cec5c 100644
--- a/src/spec/ruby/rack/filter_spec.rb
+++ b/src/spec/ruby/rack/filter_spec.rb
@@ -15,85 +15,85 @@
def stub_request(path_info)
@request = javax.servlet.http.HttpServletRequest.impl {}
- @request.stub(:setAttribute)
+ allow(@request).to receive(:setAttribute)
if block_given?
yield @request, path_info
else
- @request.stub(:getPathInfo).and_return nil
- @request.stub(:getServletPath).and_return "/some/uri#{path_info}"
+ allow(@request).to receive(:getPathInfo).and_return nil
+ allow(@request).to receive(:getServletPath).and_return "/some/uri#{path_info}"
end
- @request.stub(:getRequestURI).and_return "/some/uri#{path_info}"
+ allow(@request).to receive(:getRequestURI).and_return "/some/uri#{path_info}"
end
before :each do
stub_request("/index")
@response = javax.servlet.http.HttpServletResponse.impl {}
- @rack_context.stub(:getResource).and_return nil
- @rack_config.stub(:getProperty) do |key, default|
- ( key || raise("missing key") ) && default
+ allow(@rack_context).to receive(:getResource).and_return nil
+ allow(@rack_config).to receive(:getProperty) do |key, default|
+ (key || raise("missing key")) && default
end
- @rack_config.stub(:getBooleanProperty) do |key, default|
- ( key || raise("missing key") ) && default
+ allow(@rack_config).to receive(:getBooleanProperty) do |key, default|
+ (key || raise("missing key")) && default
end
filter.setAddsHtmlToPathInfo(true)
end
it "should dispatch the filter chain and finish if the chain resulted in a successful response" do
- chain.should_receive(:doFilter).ordered do |_, resp|
+ expect(chain).to receive(:doFilter).ordered do |_, resp|
resp.setStatus(200)
end
- @response.should_receive(:setStatus).ordered.with(200)
+ expect(@response).to receive(:setStatus).ordered.with(200)
filter.doFilter(@request, @response, chain)
end
it "should finish if the chain resulted in a redirect" do
- chain.should_receive(:doFilter).ordered do |_, resp|
+ expect(chain).to receive(:doFilter).ordered do |_, resp|
resp.sendRedirect("/some/url")
end
- @response.should_receive(:sendRedirect).ordered.with("/some/url")
+ expect(@response).to receive(:sendRedirect).ordered.with("/some/url")
filter.doFilter(@request, @response, chain)
end
it "dispatches to the rack dispatcher if the chain resulted in a 404" do
- chain.should_receive(:doFilter).ordered do |_, resp|
+ expect(chain).to receive(:doFilter).ordered do |_, resp|
resp.sendError(404)
end
- @response.should_receive(:reset).ordered
- @request.should_receive(:setAttribute).ordered.with(org.jruby.rack.RackEnvironment::DYNAMIC_REQS_ONLY, true)
- dispatcher.should_receive(:process).ordered
+ expect(@response).to receive(:reset).ordered
+ expect(@request).to receive(:setAttribute).ordered.with(org.jruby.rack.RackEnvironment::DYNAMIC_REQS_ONLY, true)
+ expect(dispatcher).to receive(:process).ordered
filter.doFilter(@request, @response, chain)
end
it "dispatches to the rack dispatcher if the chain resulted in a 403" do
# sending a PUT up the chain results in a 403 on Tomcat
# @see https://github.com/jruby/jruby-rack/issues/105
- chain.should_receive(:doFilter).ordered do |_, resp|
+ expect(chain).to receive(:doFilter).ordered do |_, resp|
resp.sendError(403)
end
- @response.should_receive(:reset).ordered
- dispatcher.should_receive(:process).ordered
+ expect(@response).to receive(:reset).ordered
+ expect(dispatcher).to receive(:process).ordered
filter.doFilter(@request, @response, chain)
end
it "dispatches to the rack dispatcher if the chain resulted in a 405" do
# PUT/DELETE up the chain end up as HTTP 405 on Jetty
# @see https://github.com/jruby/jruby-rack/issues/109
- chain.should_receive(:doFilter).ordered do |_, resp|
+ expect(chain).to receive(:doFilter).ordered do |_, resp|
resp.sendError(405)
end
- @response.should_receive(:reset).ordered
- dispatcher.should_receive(:process).ordered
+ expect(@response).to receive(:reset).ordered
+ expect(dispatcher).to receive(:process).ordered
filter.doFilter(@request, @response, chain)
end
-
+
it "dispatches to the rack dispatcher if the chain resulted in a 501" do
# non standard verbs like PATCH produce HTTP 501
# see also http://httpstatus.es/501 and http://tools.ietf.org/html/rfc5789
- chain.should_receive(:doFilter).ordered do |_, resp|
+ expect(chain).to receive(:doFilter).ordered do |_, resp|
resp.sendError(501)
end
- @response.should_receive(:reset)
- dispatcher.should_receive(:process)
+ expect(@response).to receive(:reset)
+ expect(dispatcher).to receive(:process)
filter.doFilter(@request, @response, chain)
end
@@ -101,63 +101,63 @@ def stub_request(path_info)
filter = Class.new(org.jruby.rack.RackFilter) do
def wrapResponse(response)
capture = super
- capture.setNotHandledStatuses [ 442 ]
+ capture.setNotHandledStatuses [442]
capture
end
end.new(dispatcher, @rack_context)
- chain.should_receive(:doFilter).ordered do |_, resp|
+ expect(chain).to receive(:doFilter).ordered do |_, resp|
resp.sendError(442)
end
- @response.should_receive(:reset).ordered
- dispatcher.should_receive(:process).ordered
+ expect(@response).to receive(:reset).ordered
+ expect(dispatcher).to receive(:process).ordered
filter.doFilter(@request, @response, chain)
end
it "allows downstream entities to flush the buffer in the case of a successful response" do
- chain.should_receive(:doFilter).ordered do |_, resp|
+ expect(chain).to receive(:doFilter).ordered do |_, resp|
resp.setStatus(200)
resp.flushBuffer
end
- @response.should_receive(:setStatus).ordered.with(200)
- @response.should_receive(:flushBuffer).ordered
- dispatcher.should_not_receive(:process)
+ expect(@response).to receive(:setStatus).ordered.with(200)
+ expect(@response).to receive(:flushBuffer).ordered
+ expect(dispatcher).not_to receive(:process)
filter.doFilter(@request, @response, chain)
end
it "does not allow downstream entities in the chain to flush the buffer in the case of an 404" do
- chain.should_receive(:doFilter).ordered do |_, resp|
+ expect(chain).to receive(:doFilter).ordered do |_, resp|
resp.sendError(404)
resp.flushBuffer
end
- @response.should_not_receive(:flushBuffer)
- @response.should_receive(:reset)
- dispatcher.should_receive(:process)
+ expect(@response).not_to receive(:flushBuffer)
+ expect(@response).to receive(:reset)
+ expect(dispatcher).to receive(:process)
filter.doFilter(@request, @response, chain)
end
it "only resets the buffer for a 404 if configured so" do
- chain.should_receive(:doFilter).ordered do |_, resp|
+ expect(chain).to receive(:doFilter).ordered do |_, resp|
resp.sendError(404)
resp.flushBuffer
end
- @response.should_not_receive(:flushBuffer)
- @response.should_receive(:resetBuffer)
- @response.should_not_receive(:reset)
- dispatcher.should_receive(:process)
+ expect(@response).not_to receive(:flushBuffer)
+ expect(@response).to receive(:resetBuffer)
+ expect(@response).not_to receive(:reset)
+ expect(dispatcher).to receive(:process)
filter.setResetUnhandledResponseBuffer(true)
filter.doFilter(@request, @response, chain)
end
it "allows an error response from the filter chain (and flushes the buffer)" do
- chain.should_receive(:doFilter).ordered do |_, resp|
+ expect(chain).to receive(:doFilter).ordered do |_, resp|
resp.sendError(401)
resp.flushBuffer
end
- @response.should_receive(:sendError).with(401).ordered
- @response.should_receive(:flushBuffer).ordered
- @response.should_not_receive(:reset)
- dispatcher.should_not_receive(:process)
+ expect(@response).to receive(:sendError).with(401).ordered
+ expect(@response).to receive(:flushBuffer).ordered
+ expect(@response).not_to receive(:reset)
+ expect(dispatcher).not_to receive(:process)
filter.doFilter(@request, @response, chain)
end
@@ -165,46 +165,48 @@ def wrapResponse(response)
filter = Class.new(org.jruby.rack.RackFilter) do
def wrapResponse(response)
Class.new(org.jruby.rack.servlet.ResponseCapture) do
- def isHandled(arg); getStatus < 400; end
+ def isHandled(arg)
+ ; getStatus < 400;
+ end
end.new(response)
end
end.new(dispatcher, @rack_context)
- chain.should_receive(:doFilter).ordered do |_, resp|
+ expect(chain).to receive(:doFilter).ordered do |_, resp|
resp.sendError(401)
resp.flushBuffer
end
- @response.should_not_receive(:flushBuffer)
- @response.should_receive(:reset)
- dispatcher.should_receive(:process)
+ expect(@response).not_to receive(:flushBuffer)
+ expect(@response).to receive(:reset)
+ expect(dispatcher).to receive(:process)
filter.doFilter(@request, @response, chain)
end
it "should only add to path info if it already was non-null" do
- stub_request("/index") do |request,path_info|
- request.stub(:getPathInfo).and_return path_info
- request.stub(:getServletPath).and_return "/some/uri"
- end
- chain.should_receive(:doFilter).ordered do |req,resp|
- req.getPathInfo.should == "/index.html"
- req.getServletPath.should == "/some/uri"
- req.getRequestURI.should == "/some/uri/index.html"
+ stub_request("/index") do |request, path_info|
+ allow(request).to receive(:getPathInfo).and_return path_info
+ allow(request).to receive(:getServletPath).and_return "/some/uri"
+ end
+ expect(chain).to receive(:doFilter).ordered do |req, resp|
+ expect(req.getPathInfo).to eq "/index.html"
+ expect(req.getServletPath).to eq "/some/uri"
+ expect(req.getRequestURI).to eq "/some/uri/index.html"
resp.setStatus(200)
end
- @response.should_receive(:setStatus).ordered.with(200)
+ expect(@response).to receive(:setStatus).ordered.with(200)
filter.doFilter(@request, @response, chain)
end
it "should set status to 404 when dispatcher's status is not found" do
- chain.should_receive(:doFilter).ordered do |_, resp|
+ expect(chain).to receive(:doFilter).ordered do |_, resp|
resp.sendError(404) # 404 status is irrelevant here !
end
- @response.should_receive(:reset).ordered
- @request.should_receive(:setAttribute).ordered.with(org.jruby.rack.RackEnvironment::DYNAMIC_REQS_ONLY, true)
- dispatcher.should_receive(:process).ordered do |_, resp|
+ expect(@response).to receive(:reset).ordered
+ expect(@request).to receive(:setAttribute).ordered.with(org.jruby.rack.RackEnvironment::DYNAMIC_REQS_ONLY, true)
+ expect(dispatcher).to receive(:process).ordered do |_, resp|
resp.setStatus(404)
end
- @response.should_receive(:setStatus).ordered.with(404)
+ expect(@response).to receive(:setStatus).ordered.with(404)
filter.doFilter(@request, @response, chain)
end
@@ -216,55 +218,55 @@ def isHandled(arg); getStatus < 400; end
it "should dispatch /some/uri/index.html unchanged" do
stub_request("/index.html")
- chain.should_receive(:doFilter).ordered do |req,resp|
- req.getRequestURI.should == "/some/uri/index.html"
+ expect(chain).to receive(:doFilter).ordered do |req, resp|
+ expect(req.getRequestURI).to eq "/some/uri/index.html"
resp.setStatus(200)
end
- @response.should_receive(:setStatus).ordered.with(200)
+ expect(@response).to receive(:setStatus).ordered.with(200)
filter.doFilter(@request, @response, chain)
end
it "should convert / to /index.html" do
stub_request("/")
- chain.should_receive(:doFilter).ordered do |req,resp|
- req.getServletPath.should == "/some/uri/index.html"
+ expect(chain).to receive(:doFilter).ordered do |req, resp|
+ expect(req.getServletPath).to eq "/some/uri/index.html"
resp.setStatus(200)
end
- @response.should_receive(:setStatus).ordered.with(200)
+ expect(@response).to receive(:setStatus).ordered.with(200)
filter.doFilter(@request, @response, chain)
end
it "should dispatch the request unwrapped if servlet path already contains the welcome filename" do
stub_request("/") do |request, path_info|
- request.stub(:getPathInfo).and_return nil
- request.stub(:getServletPath).and_return "/some/uri/index.html"
+ allow(request).to receive(:getPathInfo).and_return nil
+ allow(request).to receive(:getServletPath).and_return "/some/uri/index.html"
end
- chain.should_receive(:doFilter).ordered do |req,resp|
- req.getPathInfo.should == nil
- req.getServletPath.should == "/some/uri/index.html"
- req.getRequestURI.should == "/some/uri/"
+ expect(chain).to receive(:doFilter).ordered do |req, resp|
+ expect(req.getPathInfo).to eq nil
+ expect(req.getServletPath).to eq "/some/uri/index.html"
+ expect(req.getRequestURI).to eq "/some/uri/"
resp.setStatus(200)
end
- @response.should_receive(:setStatus).ordered.with(200)
+ expect(@response).to receive(:setStatus).ordered.with(200)
filter.doFilter(@request, @response, chain)
end
it "should add .html to the path" do
stub_request("")
- chain.should_receive(:doFilter).ordered do |req,resp|
- req.getServletPath.should == "/some/uri.html"
+ expect(chain).to receive(:doFilter).ordered do |req, resp|
+ expect(req.getServletPath).to eq "/some/uri.html"
resp.setStatus(200)
end
- @response.should_receive(:setStatus).ordered.with(200)
+ expect(@response).to receive(:setStatus).ordered.with(200)
filter.doFilter(@request, @response, chain)
end
it "should process dispatching when chain throws a FileNotFoundException (WAS 8.0 behavior)" do
stub_request("/foo")
- chain.should_receive(:doFilter).ordered do
+ expect(chain).to receive(:doFilter).ordered do
raise java.io.FileNotFoundException.new("/foo.html")
end
- dispatcher.should_receive(:process)
+ expect(dispatcher).to receive(:process)
filter.doFilter(@request, @response, chain)
end
@@ -277,12 +279,12 @@ def isHandled(arg); getStatus < 400; end
end
it "dispatches /some/uri/index unchanged" do
- chain.should_receive(:doFilter).ordered do |req,resp|
- req.getServletPath.should == "/some/uri/index"
- req.getRequestURI.should == "/some/uri/index"
+ expect(chain).to receive(:doFilter).ordered do |req, resp|
+ expect(req.getServletPath).to eq "/some/uri/index"
+ expect(req.getRequestURI).to eq "/some/uri/index"
resp.setStatus(200)
end
- @response.should_receive(:setStatus).ordered.with(200)
+ expect(@response).to receive(:setStatus).ordered.with(200)
filter.doFilter(@request, @response, chain)
end
end
@@ -295,43 +297,43 @@ def isHandled(arg); getStatus < 400; end
end
it "dispatches /some/uri/index unchanged if the resource does not exist" do
- chain.should_receive(:doFilter).ordered do |req,resp|
- req.getRequestURI.should == "/some/uri/index"
+ expect(chain).to receive(:doFilter).ordered do |req, resp|
+ expect(req.getRequestURI).to eq "/some/uri/index"
resp.setStatus(200)
end
- @response.should_receive(:setStatus).ordered.with(200)
+ expect(@response).to receive(:setStatus).ordered.with(200)
filter.doFilter(@request, @response, chain)
end
it "should dispatch /some/uri/index to the filter chain as /some/uri/index.html if the resource exists" do
- @rack_context.should_receive(:getResource).with("/some/uri/index.html").and_return java.net.URL.new("file://some/uri/index.html")
- chain.should_receive(:doFilter).ordered do |req,resp|
- req.getRequestURI.should == "/some/uri/index.html"
+ expect(@rack_context).to receive(:getResource).with("/some/uri/index.html").and_return java.net.URL.new("file://some/uri/index.html")
+ expect(chain).to receive(:doFilter).ordered do |req, resp|
+ expect(req.getRequestURI).to eq "/some/uri/index.html"
resp.setStatus(200)
end
- @response.should_receive(:setStatus).ordered.with(200)
+ expect(@response).to receive(:setStatus).ordered.with(200)
filter.doFilter(@request, @response, chain)
end
it "should dispatch /some/uri/ to /some/uri/index.html if the resource exists" do
- @rack_context.should_receive(:getResource).with("/some/uri/index.html").and_return java.net.URL.new("file://some/uri/index.html")
+ expect(@rack_context).to receive(:getResource).with("/some/uri/index.html").and_return java.net.URL.new("file://some/uri/index.html")
stub_request("/")
- chain.should_receive(:doFilter).ordered do |req,resp|
- req.getRequestURI.should == "/some/uri/index.html"
+ expect(chain).to receive(:doFilter).ordered do |req, resp|
+ expect(req.getRequestURI).to eq "/some/uri/index.html"
resp.setStatus(200)
end
- @response.should_receive(:setStatus).ordered.with(200)
+ expect(@response).to receive(:setStatus).ordered.with(200)
filter.doFilter(@request, @response, chain)
end
it "should dispatch to /some/uri.html if the resource exists and there is no path info" do
- @rack_context.should_receive(:getResource).with("/some/uri.html").and_return java.net.URL.new("file://some/uri.html")
+ expect(@rack_context).to receive(:getResource).with("/some/uri.html").and_return java.net.URL.new("file://some/uri.html")
stub_request("")
- chain.should_receive(:doFilter).ordered do |req,resp|
- req.getServletPath.should == "/some/uri.html"
+ expect(chain).to receive(:doFilter).ordered do |req, resp|
+ expect(req.getServletPath).to eq "/some/uri.html"
resp.setStatus(200)
end
- @response.should_receive(:setStatus).ordered.with(200)
+ expect(@response).to receive(:setStatus).ordered.with(200)
filter.doFilter(@request, @response, chain)
end
end
@@ -361,24 +363,24 @@ def isHandled(arg); getStatus < 400; end
filter.init(config)
response_capture = filter.wrapResponse(@response)
response_capture.setStatus(403)
- response_capture.isHandled.should be false
+ expect(response_capture.isHandled).to be false
response_capture.setStatus(404)
- response_capture.isHandled.should be false
+ expect(response_capture.isHandled).to be false
response_capture.setStatus(501)
- response_capture.isHandled.should be false
+ expect(response_capture.isHandled).to be false
response_capture.setStatus(504)
- response_capture.isHandled.should be false
+ expect(response_capture.isHandled).to be false
response_capture.setStatus(505)
- response_capture.isHandled.should be true
+ expect(response_capture.isHandled).to be true
end
it "should destroy dispatcher on destroy" do
- dispatcher.should_receive(:destroy)
+ expect(dispatcher).to receive(:destroy)
filter.destroy
end
it "should have default constructor (for servlet container)" do
- lambda { org.jruby.rack.RackFilter.new }.should_not raise_error
+ expect { org.jruby.rack.RackFilter.new }.not_to raise_error
end
end
diff --git a/src/spec/ruby/rack/handler/servlet_spec.rb b/src/spec/ruby/rack/handler/servlet_spec.rb
index b24d7cd0a..a04c6b289 100644
--- a/src/spec/ruby/rack/handler/servlet_spec.rb
+++ b/src/spec/ruby/rack/handler/servlet_spec.rb
@@ -6,9 +6,17 @@
describe Rack::Handler::Servlet do
class TestRackApp
- def call(env); @_env = env; [ 200, {}, '' ] end
- def _called?; !! @_env end
- def _env; @_env end
+ def call(env)
+ ; @_env = env; [200, {}, '']
+ end
+
+ def _called?
+ !!@_env
+ end
+
+ def _env
+ @_env
+ end
end
let(:app) { TestRackApp.new }
@@ -36,10 +44,10 @@ def _env; @_env end
it "creates a hash with the Rack variables in it" do
hash = servlet.create_env(@servlet_env)
- hash['rack.version'].should == Rack::VERSION
- hash['rack.multithread'].should == true
- hash['rack.multiprocess'].should == false
- hash['rack.run_once'].should == false
+ expect(hash['rack.version']).to eq Rack::VERSION
+ expect(hash['rack.multithread']).to eq true
+ expect(hash['rack.multiprocess']).to eq false
+ expect(hash['rack.run_once']).to eq false
end
it "adds all attributes from the servlet request" do
@@ -47,8 +55,8 @@ def _env; @_env end
@servlet_request.setAttribute("custom.attribute", true)
env = servlet.create_env @servlet_env
- env["PATH_INFO"].should == "/path/info"
- env["custom.attribute"].should == true
+ expect(env["PATH_INFO"]).to eq "/path/info"
+ expect(env["custom.attribute"]).to eq true
end
it "is able to override cgi variables with request attributes of the same name" do
@@ -64,20 +72,20 @@ def _env; @_env end
"REMOTE_ADDR" => "192.168.0.1",
"REMOTE_USER" => "override"
}.each { |name, value| @servlet_request.setAttribute(name, value) }
- @rack_context.stub(:getServerInfo).and_return 'Trinidad RULEZZ!'
+ allow(@rack_context).to receive(:getServerInfo).and_return 'Trinidad RULEZZ!'
env = servlet.create_env @servlet_env
- env["REQUEST_METHOD"].should == "POST"
- env["SCRIPT_NAME"].should == "/override"
- env["PATH_INFO"].should == "/override"
- env["REQUEST_URI"].should == "/override"
- env["QUERY_STRING"].should == "override"
- env["SERVER_NAME"].should == "override"
- env["SERVER_PORT"].should == "8080"
- env["SERVER_SOFTWARE"].should == "servy"
- env["REMOTE_HOST"].should == "override"
- env["REMOTE_ADDR"].should == "192.168.0.1"
- env["REMOTE_USER"].should == "override"
+ expect(env["REQUEST_METHOD"]).to eq "POST"
+ expect(env["SCRIPT_NAME"]).to eq "/override"
+ expect(env["PATH_INFO"]).to eq "/override"
+ expect(env["REQUEST_URI"]).to eq "/override"
+ expect(env["QUERY_STRING"]).to eq "override"
+ expect(env["SERVER_NAME"]).to eq "override"
+ expect(env["SERVER_PORT"]).to eq "8080"
+ expect(env["SERVER_SOFTWARE"]).to eq "servy"
+ expect(env["REMOTE_HOST"]).to eq "override"
+ expect(env["REMOTE_ADDR"]).to eq "192.168.0.1"
+ expect(env["REMOTE_USER"]).to eq "override"
end
it "is able to override headers with request attributes named HTTP_*" do
@@ -95,22 +103,22 @@ def _env; @_env end
@servlet_request.setContent('12345'.to_java_bytes) # content length == 5
env = servlet.create_env @servlet_env
- env["CONTENT_TYPE"].should == "application/override"
- env["CONTENT_LENGTH"].should == "20"
- env["HTTP_HOST"].should == "override"
- env["HTTP_ACCEPT"].should == "application/*"
- env["HTTP_ACCEPT_ENCODING"].should == "bzip2"
+ expect(env["CONTENT_TYPE"]).to eq "application/override"
+ expect(env["CONTENT_LENGTH"]).to eq "20"
+ expect(env["HTTP_HOST"]).to eq "override"
+ expect(env["HTTP_ACCEPT"]).to eq "application/*"
+ expect(env["HTTP_ACCEPT_ENCODING"]).to eq "bzip2"
end
it "is not able to override CONTENT_TYPE or CONTENT_LENGTH to nil" do
- attrs = {"CONTENT_TYPE" => nil, "CONTENT_LENGTH" => -1 }
+ attrs = { "CONTENT_TYPE" => nil, "CONTENT_LENGTH" => -1 }
attrs.each { |name, value| @servlet_request.setAttribute(name, value) }
@servlet_request.setContentType('text/html')
@servlet_request.setContent('1234567890'.to_java_bytes)
env = servlet.create_env @servlet_env
- env["CONTENT_TYPE"].should == "text/html"
- env["CONTENT_LENGTH"].should == "10"
+ expect(env["CONTENT_TYPE"]).to eq "text/html"
+ expect(env["CONTENT_LENGTH"]).to eq "10"
end
it "sets the rack.input and rack.errors keys" do
@@ -120,18 +128,18 @@ def _env; @_env end
env = servlet.create_env @servlet_env
- (input = env['rack.input']).should_not be nil
- [:gets, :read, :each].each { |sym| input.respond_to?(sym).should == true }
- (errors = env['rack.errors']).should_not be nil
- [:puts, :write, :flush].each { |sym| errors.respond_to?(sym).should == true }
+ expect((input = env['rack.input'])).not_to be nil
+ [:gets, :read, :each].each { |sym| expect(input.respond_to?(sym)).to eq true }
+ expect((errors = env['rack.errors'])).not_to be nil
+ [:puts, :write, :flush].each { |sym| expect(errors.respond_to?(sym)).to eq true }
end
it "sets the rack.errors to log via rack context" do
env = servlet.create_env @servlet_env
- env['rack.errors'].should be_a JRuby::Rack::ServletLog
+ expect(env['rack.errors']).to be_a(JRuby::Rack::ServletLog)
- @rack_context.should_receive(:log).with("bar").ordered
- @rack_context.should_receive(:log).with("huu").ordered
+ expect(@rack_context).to receive(:log).with("bar").ordered
+ expect(@rack_context).to receive(:log).with("huu").ordered
env['rack.errors'].puts "bar"
env['rack.errors'].write "huu"
@@ -143,7 +151,7 @@ def _env; @_env end
env = servlet.create_env @servlet_env
env['rack.url_scheme']
- env['HTTPS'].should == 'on'
+ expect(env['HTTPS']).to eq 'on'
end
it "adds cgi variables" do
@@ -161,16 +169,16 @@ def _env; @_env end
env = servlet.create_env @servlet_env
- env["REQUEST_METHOD"].should == "GET"
- env["SCRIPT_NAME"].should == "/app"
- env["PATH_INFO"].should == "/script_name/path/info"
- env["REQUEST_URI"].should == "/app/script_name/path/info?hello=there"
- env["QUERY_STRING"].should == "hello=there"
- env["SERVER_NAME"].should == "serverhost"
- env["SERVER_PORT"].should == "80"
- env["REMOTE_HOST"].should == "localhost"
- env["REMOTE_ADDR"].should == "127.0.0.1"
- env["REMOTE_USER"].should == "admin"
+ expect(env["REQUEST_METHOD"]).to eq "GET"
+ expect(env["SCRIPT_NAME"]).to eq "/app"
+ expect(env["PATH_INFO"]).to eq "/script_name/path/info"
+ expect(env["REQUEST_URI"]).to eq "/app/script_name/path/info?hello=there"
+ expect(env["QUERY_STRING"]).to eq "hello=there"
+ expect(env["SERVER_NAME"]).to eq "serverhost"
+ expect(env["SERVER_PORT"]).to eq "80"
+ expect(env["REMOTE_HOST"]).to eq "localhost"
+ expect(env["REMOTE_ADDR"]).to eq "127.0.0.1"
+ expect(env["REMOTE_USER"]).to eq "admin"
end
it "adds all variables under normal operation" do
@@ -191,25 +199,25 @@ def _env; @_env end
{ "Host" => "serverhost",
"Accept" => "text/*",
- "Accept-Encoding" => "gzip"}.each do |name, value|
+ "Accept-Encoding" => "gzip" }.each do |name, value|
@servlet_request.addHeader(name, value)
end
env = servlet.create_env @servlet_env
- env["rack.version"].should == Rack::VERSION
- env["CONTENT_TYPE"].should == "text/html"
- env["HTTP_HOST"].should == "serverhost"
- env["HTTP_ACCEPT"].should == "text/*"
- env["REQUEST_METHOD"].should == "GET"
- env["SCRIPT_NAME"].should == "/app"
- env["PATH_INFO"].should == "/script_name/path/info"
- env["REQUEST_URI"].should == "/app/script_name/path/info?hello=there"
- env["QUERY_STRING"].should == "hello=there"
- env["SERVER_NAME"].should == "serverhost"
- env["SERVER_PORT"].should == "80"
- env["REMOTE_HOST"].should == "localhost"
- env["REMOTE_ADDR"].should == "127.0.0.1"
- env["REMOTE_USER"].should == "admin"
+ expect(env["rack.version"]).to eq Rack::VERSION
+ expect(env["CONTENT_TYPE"]).to eq "text/html"
+ expect(env["HTTP_HOST"]).to eq "serverhost"
+ expect(env["HTTP_ACCEPT"]).to eq "text/*"
+ expect(env["REQUEST_METHOD"]).to eq "GET"
+ expect(env["SCRIPT_NAME"]).to eq "/app"
+ expect(env["PATH_INFO"]).to eq "/script_name/path/info"
+ expect(env["REQUEST_URI"]).to eq "/app/script_name/path/info?hello=there"
+ expect(env["QUERY_STRING"]).to eq "hello=there"
+ expect(env["SERVER_NAME"]).to eq "serverhost"
+ expect(env["SERVER_PORT"]).to eq "80"
+ expect(env["REMOTE_HOST"]).to eq "localhost"
+ expect(env["REMOTE_ADDR"]).to eq "127.0.0.1"
+ expect(env["REMOTE_USER"]).to eq "admin"
end
it "sets environment variables to the empty string if their value is nil" do
@@ -219,15 +227,15 @@ def _env; @_env end
@servlet_request.setRemoteAddr(nil) # default '127.0.0.1'
env = servlet.create_env @servlet_env
- env["REQUEST_METHOD"].should == "GET"
- env["SCRIPT_NAME"].should == ""
- env["PATH_INFO"].should == ""
- env["REQUEST_URI"].should == ""
- env["QUERY_STRING"].should == ""
- env["SERVER_NAME"].should == ""
- env["REMOTE_HOST"].should == ""
- env["REMOTE_ADDR"].should == ""
- env["REMOTE_USER"].should == ""
+ expect(env["REQUEST_METHOD"]).to eq "GET"
+ expect(env["SCRIPT_NAME"]).to eq ""
+ expect(env["PATH_INFO"]).to eq ""
+ expect(env["REQUEST_URI"]).to eq ""
+ expect(env["QUERY_STRING"]).to eq ""
+ expect(env["SERVER_NAME"]).to eq ""
+ expect(env["REMOTE_HOST"]).to eq ""
+ expect(env["REMOTE_ADDR"]).to eq ""
+ expect(env["REMOTE_USER"]).to eq ""
end
it "calculates path info from the servlet path and the path info" do
@@ -235,8 +243,8 @@ def _env; @_env end
@servlet_request.setServletPath('/path')
env = servlet.create_env @servlet_env
- env["SCRIPT_NAME"].should == "/context"
- env["PATH_INFO"].should == "/path"
+ expect(env["SCRIPT_NAME"]).to eq "/context"
+ expect(env["PATH_INFO"]).to eq "/path"
end
it "works correctly when running under the root context" do
@@ -244,8 +252,8 @@ def _env; @_env end
@servlet_request.setServletPath('/')
env = servlet.create_env @servlet_env
- env["PATH_INFO"].should == "/"
- env["SCRIPT_NAME"].should == ""
+ expect(env["PATH_INFO"]).to eq "/"
+ expect(env["SCRIPT_NAME"]).to eq ""
end
it "ignores servlet path when it is not part of the request URI" do
@@ -255,8 +263,8 @@ def _env; @_env end
@servlet_request.setRequestURI('/context/')
env = servlet.create_env @servlet_env
- env["SCRIPT_NAME"].should == "/context"
- env["PATH_INFO"].should == "/"
+ expect(env["SCRIPT_NAME"]).to eq "/context"
+ expect(env["PATH_INFO"]).to eq "/"
end
it "includes query string in the request URI" do
@@ -264,7 +272,7 @@ def _env; @_env end
@servlet_request.setQueryString('some=query&string')
env = servlet.create_env @servlet_env
- env["REQUEST_URI"].should == "/some/path?some=query&string"
+ expect(env["REQUEST_URI"]).to eq "/some/path?some=query&string"
end
it "puts content type and content length in the hash without the HTTP_ prefix" do
@@ -273,12 +281,12 @@ def _env; @_env end
@servlet_request.setContent('0123456789'.to_java_bytes) # length 10
env = servlet.create_env @servlet_env
- env["CONTENT_TYPE"].should == "text/html"
- env["CONTENT_LENGTH"].should == "10"
- env["HTTP_CONTENT_TYPE"].should == nil
- env.should_not have_key("HTTP_CONTENT_TYPE")
- env["HTTP_CONTENT_LENGTH"].should == nil
- env.should_not have_key("HTTP_CONTENT_LENGTH")
+ expect(env["CONTENT_TYPE"]).to eq "text/html"
+ expect(env["CONTENT_LENGTH"]).to eq "10"
+ expect(env["HTTP_CONTENT_TYPE"]).to eq nil
+ expect(env).not_to have_key("HTTP_CONTENT_TYPE")
+ expect(env["HTTP_CONTENT_LENGTH"]).to eq nil
+ expect(env).not_to have_key("HTTP_CONTENT_LENGTH")
end
it "puts the other headers in the hash upcased and underscored and prefixed with HTTP_" do
@@ -289,13 +297,13 @@ def _env; @_env end
}.each { |name, value| @servlet_request.addHeader(name, value) }
env = servlet.create_env @servlet_env
- env["CONTENT_TYPE"].should == nil
- env.should_not have_key("CONTENT_TYPE")
- env["CONTENT_LENGTH"].should == nil
- env.should_not have_key("CONTENT_LENGTH")
- env["HTTP_HOST"].should == "localhost"
- env["HTTP_ACCEPT"].should == "text/*"
- env["HTTP_ACCEPT_ENCODING"].should == "gzip"
+ expect(env["CONTENT_TYPE"]).to eq nil
+ expect(env).not_to have_key("CONTENT_TYPE")
+ expect(env["CONTENT_LENGTH"]).to eq nil
+ expect(env).not_to have_key("CONTENT_LENGTH")
+ expect(env["HTTP_HOST"]).to eq "localhost"
+ expect(env["HTTP_ACCEPT"]).to eq "text/*"
+ expect(env["HTTP_ACCEPT_ENCODING"]).to eq "gzip"
end
it "handles header names that have more than one dash in them" do
@@ -306,30 +314,30 @@ def _env; @_env end
}.each { |name, value| @servlet_request.addHeader(name, value) }
env = servlet.create_env @servlet_env
- env["HTTP_X_FORWARDED_PROTO"].should == "https"
- env["HTTP_IF_NONE_MATCH"].should == "abcdef"
- env["HTTP_IF_MODIFIED_SINCE"].should == "today"
- env["HTTP_X_SOME_REALLY_LONG_HEADER"].should == "yeap"
+ expect(env["HTTP_X_FORWARDED_PROTO"]).to eq "https"
+ expect(env["HTTP_IF_NONE_MATCH"]).to eq "abcdef"
+ expect(env["HTTP_IF_MODIFIED_SINCE"]).to eq "today"
+ expect(env["HTTP_X_SOME_REALLY_LONG_HEADER"]).to eq "yeap"
end
it "exposes the servlet request" do
env = servlet.create_env @servlet_env
- expect( env['java.servlet_request'] ).to be @servlet_request
+ expect(env['java.servlet_request']).to be @servlet_request
end
it "exposes the servlet response" do
env = servlet.create_env @servlet_env
- expect( env['java.servlet_response'] ).to be @servlet_response
+ expect(env['java.servlet_response']).to be @servlet_response
end
it "exposes the servlet context xxxx" do
env = servlet.create_env @servlet_env
- expect( env['java.servlet_context'] ).to be_a javax.servlet.ServletContext
+ expect(env['java.servlet_context']).to be_a javax.servlet.ServletContext
end
it "exposes the rack context" do
env = servlet.create_env @servlet_env
- expect( env['jruby.rack.context'] ).to be @rack_context
+ expect(env['jruby.rack.context']).to be @rack_context
end
it "retrieves hidden attribute" do
@@ -352,12 +360,12 @@ def getAttributeNames
env = servlet.create_env servlet_env
- expect( env.keys ).to include 'current_page'
- expect( env.keys ).to include 'org.answer.internal'
- expect( env.keys ).to_not include 'org.apache.internal'
+ expect(env.keys).to include 'current_page'
+ expect(env.keys).to include 'org.answer.internal'
+ expect(env.keys).to_not include 'org.apache.internal'
- expect( env['org.answer.internal'] ).to be 4200
- expect( env['org.apache.internal'] ).to be true
+ expect(env['org.answer.internal']).to be 4200
+ expect(env['org.apache.internal']).to be true
end
it "sets attributes with false/null values" do
@@ -370,11 +378,11 @@ def getAttributeNames
env = servlet.create_env @servlet_env
- expect( env['org.false'] ).to be false
- expect( env['null.attr'] ).to be nil
- expect( env['the.truth'] ).to be true
+ expect(env['org.false']).to be false
+ expect(env['null.attr']).to be nil
+ expect(env['the.truth']).to be true
- expect( env.keys ).to include 'org.false'
+ expect(env.keys).to include 'org.false'
end
it "works like a Hash (fetching values)" do
@@ -386,12 +394,12 @@ def getAttributeNames
env['attr2'] = false
env['attr3'] = nil
- expect( env.fetch('attr1', 11) ).to eql 1
- expect( env.fetch('attr2', true) ).to eql false
- expect( env['attr2'] ).to eql false
- expect( env.fetch('attr3', 33) ).to eql nil
- expect( env['attr4'] ).to eql nil
- expect( env.fetch('attr4') { 42 } ).to eql 42
+ expect(env.fetch('attr1', 11)).to eql 1
+ expect(env.fetch('attr2', true)).to eql false
+ expect(env['attr2']).to eql false
+ expect(env.fetch('attr3', 33)).to eql nil
+ expect(env['attr4']).to eql nil
+ expect(env.fetch('attr4') { 42 }).to eql 42
expect { env.fetch('attr4') }.to raise_error # KeyError
end
@@ -413,11 +421,11 @@ def getAttributeNames
# { "foo" => "0", "bar[" => "1", "baz_" => "2", "meh" => "3" }
- expect( rack_request.GET['foo'] ).to eql('0')
- expect( rack_request.GET['baz_'] ).to eql('2')
- expect( rack_request.GET['meh'] ).to eql('3')
+ expect(rack_request.GET['foo']).to eql('0')
+ expect(rack_request.GET['baz_']).to eql('2')
+ expect(rack_request.GET['meh']).to eql('3')
- expect( rack_request.query_string ).to eql 'foo]=0&bar[=1&baz_=2&[meh=3'
+ expect(rack_request.query_string).to eql 'foo]=0&bar[=1&baz_=2&[meh=3'
end
it "parses nestedx request parameters (Rack-compat)" do
@@ -439,17 +447,17 @@ def getAttributeNames
env = servlet.create_env(@servlet_env)
rack_request = Rack::Request.new(env)
- #params = { "foo" => { "bar" => "2", "baz" => "1", "meh" => [ nil, nil ] }, "huh" => { "1" => "b", "0" => "a" } }
- #expect( rack_request.GET ).to eql(params)
+ # params = { "foo" => { "bar" => "2", "baz" => "1", "meh" => [ nil, nil ] }, "huh" => { "1" => "b", "0" => "a" } }
+ # expect(rack_request.GET).to eql(params)
- expect( rack_request.GET['foo']['bar'] ).to eql('2')
- expect( rack_request.GET['foo']['baz'] ).to eql('1')
- expect( rack_request.params['foo']['meh'] ).to be_a Array
- expect( rack_request.params['huh'] ).to eql({ "1" => "b", "0" => "a" })
+ expect(rack_request.GET['foo']['bar']).to eql('2')
+ expect(rack_request.GET['foo']['baz']).to eql('1')
+ expect(rack_request.params['foo']['meh']).to be_a Array
+ expect(rack_request.params['huh']).to eql({ "1" => "b", "0" => "a" })
- expect( rack_request.POST ).to eql Hash.new
+ expect(rack_request.POST).to eql Hash.new
- expect( rack_request.query_string ).to eql 'foo[bar]=0&foo[baz]=1&foo[bar]=2&foo[meh[]]=x&foo[meh[]]=42&huh[1]=b&huh[0]=a'
+ expect(rack_request.query_string).to eql 'foo[bar]=0&foo[baz]=1&foo[bar]=2&foo[meh[]]=x&foo[meh[]]=42&huh[1]=b&huh[0]=a'
end
it "raises if nested request parameters are broken (Rack-compat)" do
@@ -473,10 +481,10 @@ def getAttributeNames
end
expect { rack_request.GET }.to raise_error(error, "expected Hash (got Array) for param `foo'")
- rack_request.POST.should == {}
+ expect(rack_request.POST).to eq({})
expect { rack_request.params }.to raise_error(error, "expected Hash (got Array) for param `foo'")
- rack_request.query_string.should == 'foo[]=0&foo[bar]=1'
+ expect(rack_request.query_string).to eq 'foo[]=0&foo[bar]=1'
end
end
@@ -500,7 +508,7 @@ def getAttributeNames
@servlet_request.setQueryString('hello=there')
@servlet_request.setServerName('serverhost')
@servlet_request.setServerPort(80)
- @rack_context.stub(:getServerInfo).and_return 'Trinidad'
+ allow(@rack_context).to receive(:getServerInfo).and_return 'Trinidad'
@servlet_request.setRemoteAddr('127.0.0.1')
@servlet_request.setRemoteHost('localhost')
@servlet_request.setRemoteUser('admin')
@@ -517,43 +525,43 @@ def getAttributeNames
it "is a Hash" do
env = servlet.create_env filled_servlet_env
- expect( env ).to be_a Hash
+ expect(env).to be_a Hash
end
it "is not lazy by default" do
env = servlet.create_env filled_servlet_env
- env.keys.should include('REQUEST_METHOD')
- env.keys.should include('SCRIPT_NAME')
- env.keys.should include('PATH_INFO')
- env.keys.should include('REQUEST_URI')
- env.keys.should include('QUERY_STRING')
- env.keys.should include('SERVER_NAME')
- env.keys.should include('SERVER_PORT')
- env.keys.should include('REMOTE_HOST')
- env.keys.should include('REMOTE_ADDR')
- env.keys.should include('REMOTE_USER')
+ expect(env.keys).to include('REQUEST_METHOD')
+ expect(env.keys).to include('SCRIPT_NAME')
+ expect(env.keys).to include('PATH_INFO')
+ expect(env.keys).to include('REQUEST_URI')
+ expect(env.keys).to include('QUERY_STRING')
+ expect(env.keys).to include('SERVER_NAME')
+ expect(env.keys).to include('SERVER_PORT')
+ expect(env.keys).to include('REMOTE_HOST')
+ expect(env.keys).to include('REMOTE_ADDR')
+ expect(env.keys).to include('REMOTE_USER')
Rack::Handler::Servlet::DefaultEnv::BUILTINS.each do |key|
- env.keys.should include(key)
+ expect(env.keys).to include(key)
end
- env.keys.should include('rack.version')
- env.keys.should include('rack.input')
- env.keys.should include('rack.errors')
- env.keys.should include('rack.url_scheme')
- env.keys.should include('rack.multithread')
- env.keys.should include('rack.run_once')
- env.keys.should include('java.servlet_context')
- env.keys.should include('java.servlet_request')
- env.keys.should include('java.servlet_response')
+ expect(env.keys).to include('rack.version')
+ expect(env.keys).to include('rack.input')
+ expect(env.keys).to include('rack.errors')
+ expect(env.keys).to include('rack.url_scheme')
+ expect(env.keys).to include('rack.multithread')
+ expect(env.keys).to include('rack.run_once')
+ expect(env.keys).to include('java.servlet_context')
+ expect(env.keys).to include('java.servlet_request')
+ expect(env.keys).to include('java.servlet_response')
Rack::Handler::Servlet::DefaultEnv::VARIABLES.each do |key|
- env.keys.should include(key)
+ expect(env.keys).to include(key)
end
- env.keys.should include('HTTP_X_FORWARDED_PROTO')
- env.keys.should include('HTTP_IF_NONE_MATCH')
- env.keys.should include('HTTP_IF_MODIFIED_SINCE')
- env.keys.should include('HTTP_X_SOME_REALLY_LONG_HEADER')
+ expect(env.keys).to include('HTTP_X_FORWARDED_PROTO')
+ expect(env.keys).to include('HTTP_IF_NONE_MATCH')
+ expect(env.keys).to include('HTTP_IF_MODIFIED_SINCE')
+ expect(env.keys).to include('HTTP_X_SOME_REALLY_LONG_HEADER')
end
it "works correctly when frozen" do
@@ -564,10 +572,10 @@ def getAttributeNames
expect { env['SCRIPT_NAME'] }.to_not raise_error
Rack::Handler::Servlet::DefaultEnv::BUILTINS.each do |key|
expect { env[key] }.to_not raise_error
- env[key].should_not be nil
+ expect(env[key]).not_to be nil
end
expect { env['OTHER_METHOD'] }.to_not raise_error
- env['OTHER_METHOD'].should be nil
+ expect(env['OTHER_METHOD']).to be nil
expect { env['rack.version'] }.to_not raise_error
expect { env['rack.input'] }.to_not raise_error
@@ -578,11 +586,11 @@ def getAttributeNames
expect { env['java.servlet_request'] }.to_not raise_error
expect { env['java.servlet_response'] }.to_not raise_error
Rack::Handler::Servlet::DefaultEnv::VARIABLES.each do |key|
- lambda { env[key] }.should_not raise_error
- env[key].should_not be(nil), "key: #{key.inspect} nil"
+ expect { env[key] }.not_to raise_error
+ expect(env[key]).not_to be(nil), "key: #{key.inspect} nil"
end
expect { env['rack.whatever'] }.to_not raise_error
- env['rack.whatever'].should be nil
+ expect(env['rack.whatever']).to be nil
expect {
env['HTTP_X_FORWARDED_PROTO']
@@ -590,62 +598,62 @@ def getAttributeNames
env['HTTP_IF_MODIFIED_SINCE']
env['HTTP_X_SOME_REALLY_LONG_HEADER']
}.to_not raise_error
- env['HTTP_X_FORWARDED_PROTO'].should_not be nil
- env['HTTP_IF_NONE_MATCH'].should_not be nil
- env['HTTP_IF_MODIFIED_SINCE'].should_not be nil
- env['HTTP_X_SOME_REALLY_LONG_HEADER'].should_not be nil
+ expect(env['HTTP_X_FORWARDED_PROTO']).not_to be nil
+ expect(env['HTTP_IF_NONE_MATCH']).not_to be nil
+ expect(env['HTTP_IF_MODIFIED_SINCE']).not_to be nil
+ expect(env['HTTP_X_SOME_REALLY_LONG_HEADER']).not_to be nil
expect { env['HTTP_X_SOME_NON_EXISTENT_HEADER'] }.to_not raise_error
- env['HTTP_X_SOME_NON_EXISTENT_HEADER'].should be nil
+ expect(env['HTTP_X_SOME_NON_EXISTENT_HEADER']).to be nil
end
it "works when dupped and frozen as a request" do
env = servlet.create_env filled_servlet_env
request = Rack::Request.new(env.dup.freeze)
- lambda { request.request_method }.should_not raise_error
- request.request_method.should == 'GET'
+ expect { request.request_method }.not_to raise_error
+ expect(request.request_method).to eq 'GET'
- lambda { request.script_name }.should_not raise_error
- request.script_name.should == '/main'
+ expect { request.script_name }.not_to raise_error
+ expect(request.script_name).to eq '/main'
- lambda { request.path_info }.should_not raise_error
- request.path_info.should =~ /\/path\/info/
+ expect { request.path_info }.not_to raise_error
+ expect(request.path_info).to match(/\/path\/info/)
- lambda { request.query_string }.should_not raise_error
- request.query_string.should == 'hello=there'
+ expect { request.query_string }.not_to raise_error
+ expect(request.query_string).to eq 'hello=there'
- lambda { request.content_type }.should_not raise_error
- request.content_type.should == 'text/plain'
+ expect { request.content_type }.not_to raise_error
+ expect(request.content_type).to eq 'text/plain'
- lambda { request.content_length }.should_not raise_error
- request.content_length.should == '4'
+ expect { request.content_length }.not_to raise_error
+ expect(request.content_length).to eq '4'
- lambda { request.logger }.should_not raise_error
- request.logger.should be nil # we do not setup rack.logger
+ expect { request.logger }.not_to raise_error
+ expect(request.logger).to be nil # we do not setup rack.logger
- lambda { request.scheme }.should_not raise_error
- request.scheme.should == 'https' # X-Forwarded-Proto
+ expect { request.scheme }.not_to raise_error
+ expect(request.scheme).to eq 'https' # X-Forwarded-Proto
- lambda { request.port }.should_not raise_error
- request.port.should == 80
+ expect { request.port }.not_to raise_error
+ expect(request.port).to eq 80
- lambda { request.host_with_port }.should_not raise_error
- request.host_with_port.should == 'serverhost:80'
+ expect { request.host_with_port }.not_to raise_error
+ expect(request.host_with_port).to eq 'serverhost:80'
- lambda { request.referrer }.should_not raise_error
- request.referrer.should == 'http://www.example.com'
+ expect { request.referrer }.not_to raise_error
+ expect(request.referrer).to eq 'http://www.example.com'
- lambda { request.user_agent }.should_not raise_error
- request.user_agent.should == nil
+ expect { request.user_agent }.not_to raise_error
+ expect(request.user_agent).to eq nil
if defined?(request.base_url)
- lambda { request.base_url }.should_not raise_error
- request.base_url.should == 'https://serverhost:80'
+ expect { request.base_url }.not_to raise_error
+ expect(request.base_url).to eq 'https://serverhost:80'
end
- lambda { request.url }.should_not raise_error
- request.url.should == 'https://serverhost:80/main/app1/path/info?hello=there'
+ expect { request.url }.not_to raise_error
+ expect(request.url).to eq 'https://serverhost:80/main/app1/path/info?hello=there'
end
describe 'dumped-and-loaded' do
@@ -655,70 +663,70 @@ def getAttributeNames
it "is a DefaultEnv" do
env = servlet.create_env filled_servlet_env
- dump = Marshal.dump( env.to_hash ); env = Marshal.load(dump)
- expect( env ).to be_a Rack::Handler::Servlet::DefaultEnv
+ dump = Marshal.dump(env.to_hash); env = Marshal.load(dump)
+ expect(env).to be_a Rack::Handler::Servlet::DefaultEnv
end
it "works (almost) as before" do
env = servlet.create_env filled_servlet_env
- dump = Marshal.dump( env.to_hash )
+ dump = Marshal.dump(env.to_hash)
it_works env = Marshal.load(dump)
- expect( env['rack.input'] ).to be nil
- expect( env['rack.errors'] ).to be nil
+ expect(env['rack.input']).to be nil
+ expect(env['rack.errors']).to be nil
- expect( env['java.servlet_context'] ).to be nil
- expect( env['java.servlet_request'] ).to be nil
- expect( env['java.servlet_response'] ).to be nil
+ expect(env['java.servlet_context']).to be nil
+ expect(env['java.servlet_request']).to be nil
+ expect(env['java.servlet_response']).to be nil
end
it "initialized than dumped" do
env = servlet.create_env filled_servlet_env
it_works env
- expect( env['rack.input'] ).to_not be nil
- expect( env['rack.errors'] ).to_not be nil
+ expect(env['rack.input']).to_not be nil
+ expect(env['rack.errors']).to_not be nil
- expect( env['java.servlet_context'] ).to_not be nil
- expect( env['java.servlet_request'] ).to_not be nil
- expect( env['java.servlet_response'] ).to_not be nil
+ expect(env['java.servlet_context']).to_not be nil
+ expect(env['java.servlet_request']).to_not be nil
+ expect(env['java.servlet_response']).to_not be nil
- dump = Marshal.dump( env.to_hash )
+ dump = Marshal.dump(env.to_hash)
it_works env = Marshal.load(dump)
- expect( env['rack.input'] ).to be nil
- expect( env['rack.errors'] ).to be nil
+ expect(env['rack.input']).to be nil
+ expect(env['rack.errors']).to be nil
- expect( env['java.servlet_context'] ).to be nil
- expect( env['java.servlet_request'] ).to be nil
- expect( env['java.servlet_response'] ).to be nil
+ expect(env['java.servlet_context']).to be nil
+ expect(env['java.servlet_request']).to be nil
+ expect(env['java.servlet_response']).to be nil
end
def it_works(env)
- expect( env['REQUEST_METHOD'] ).to eql 'GET'
- expect( env['SCRIPT_NAME'] ).to eql '/main'
- expect( env['SERVER_NAME'] ).to eql 'serverhost'
- expect( env['SERVER_PORT'] ).to eql '80'
- expect( env['OTHER_METHOD'] ).to be nil
+ expect(env['REQUEST_METHOD']).to eql 'GET'
+ expect(env['SCRIPT_NAME']).to eql '/main'
+ expect(env['SERVER_NAME']).to eql 'serverhost'
+ expect(env['SERVER_PORT']).to eql '80'
+ expect(env['OTHER_METHOD']).to be nil
Rack::Handler::Servlet::DefaultEnv::VARIABLES.each do |key|
- expect( env[key] ).to_not be(nil), "key: #{key.inspect} nil"
+ expect(env[key]).to_not be(nil), "key: #{key.inspect} nil"
end
- expect( env['rack.url_scheme'] ).to_not be nil
- expect( env['rack.version'] ).to_not be nil
- expect( env['jruby.rack.version'] ).to_not be nil
+ expect(env['rack.url_scheme']).to_not be nil
+ expect(env['rack.version']).to_not be nil
+ expect(env['jruby.rack.version']).to_not be nil
- expect( env['rack.run_once'] ).to be false
- expect( env['rack.multithread'] ).to be true
+ expect(env['rack.run_once']).to be false
+ expect(env['rack.multithread']).to be true
- expect( env['rack.whatever'] ).to be nil
+ expect(env['rack.whatever']).to be nil
- expect( env['HTTP_REFERER'] ).to eql 'http://www.example.com'
- expect( env['HTTP_X_FORWARDED_PROTO'] ).to_not be nil
- expect( env['HTTP_IF_NONE_MATCH'] ).to_not be nil
- expect( env['HTTP_IF_MODIFIED_SINCE'] ).to_not be nil
- expect( env['HTTP_X_SOME_REALLY_LONG_HEADER'] ).to_not be nil
- expect( env['HTTP_X_SOME_NON_EXISTENT_HEADER'] ).to be nil
+ expect(env['HTTP_REFERER']).to eql 'http://www.example.com'
+ expect(env['HTTP_X_FORWARDED_PROTO']).to_not be nil
+ expect(env['HTTP_IF_NONE_MATCH']).to_not be nil
+ expect(env['HTTP_IF_MODIFIED_SINCE']).to_not be nil
+ expect(env['HTTP_X_SOME_REALLY_LONG_HEADER']).to_not be nil
+ expect(env['HTTP_X_SOME_NON_EXISTENT_HEADER']).to be nil
end
end
@@ -737,30 +745,30 @@ def it_works(env)
it "creates a new Hash" do
hash = new_hash
- expect( hash ).to be_a Hash
+ expect(hash).to be_a Hash
end
it "a new Hash is empty" do
hash = new_hash
- expect( hash ).to be_empty
+ expect(hash).to be_empty
end
it "allows filling a new Hash" do
hash = new_hash
hash['some'] = 'SOME'
- expect( hash['some'] ).to eql 'SOME'
+ expect(hash['some']).to eql 'SOME'
end
it "allows iterating over a new Hash" do
hash = new_hash
hash['some'] = 'SOME'
- hash['more'] =[ 'MORE' ]
- expect( hash.keys.size ).to be 2
- expect( hash.values.size ).to be 2
+ hash['more'] = ['MORE']
+ expect(hash.keys.size).to be 2
+ expect(hash.values.size).to be 2
hash.each do |key, val|
case key
- when 'some' then expect( val ).to eql 'SOME'
- when 'more' then expect( val ).to eql [ 'MORE' ]
+ when 'some' then expect(val).to eql 'SOME'
+ when 'more' then expect(val).to eql ['MORE']
else fail("unexpected #{key.inspect} = #{val.inspect}")
end
end
@@ -770,7 +778,7 @@ def it_works(env)
env = servlet.create_env(@servlet_env)
hash = env.class.new
env.keys.each { |k| hash[k] = env[k] if env.has_key?(k) }
- expect( hash.size ).to eql env.size
+ expect(hash.size).to eql env.size
end
private
@@ -811,7 +819,7 @@ def servlet.create_env(servlet_env)
servlet_request.setQueryString('hello=there')
servlet_request.setServerName('serverhost')
servlet_request.setServerPort(80)
- @rack_context.stub(:getServerInfo).and_return 'Trinidad'
+ allow(@rack_context).to receive(:getServerInfo).and_return 'Trinidad'
servlet_request.setRemoteAddr('127.0.0.1')
servlet_request.setRemoteHost('localhost')
servlet_request.setRemoteUser('admin')
@@ -833,37 +841,37 @@ def servlet.create_env(servlet_env)
it "populates on keys" do
env = servlet.create_env filled_servlet_env
- env.keys.should include('REQUEST_METHOD')
- env.keys.should include('SCRIPT_NAME')
- env.keys.should include('PATH_INFO')
- env.keys.should include('REQUEST_URI')
- env.keys.should include('QUERY_STRING')
- env.keys.should include('SERVER_NAME')
- env.keys.should include('SERVER_PORT')
- env.keys.should include('REMOTE_HOST')
- env.keys.should include('REMOTE_ADDR')
- env.keys.should include('REMOTE_USER')
+ expect(env.keys).to include('REQUEST_METHOD')
+ expect(env.keys).to include('SCRIPT_NAME')
+ expect(env.keys).to include('PATH_INFO')
+ expect(env.keys).to include('REQUEST_URI')
+ expect(env.keys).to include('QUERY_STRING')
+ expect(env.keys).to include('SERVER_NAME')
+ expect(env.keys).to include('SERVER_PORT')
+ expect(env.keys).to include('REMOTE_HOST')
+ expect(env.keys).to include('REMOTE_ADDR')
+ expect(env.keys).to include('REMOTE_USER')
Rack::Handler::Servlet::DefaultEnv::BUILTINS.each do |key|
- env.keys.should include(key)
+ expect(env.keys).to include(key)
end
- env.keys.should include('rack.version')
- env.keys.should include('rack.input')
- env.keys.should include('rack.errors')
- env.keys.should include('rack.url_scheme')
- env.keys.should include('rack.multithread')
- env.keys.should include('rack.run_once')
- env.keys.should include('java.servlet_context')
- env.keys.should include('java.servlet_request')
- env.keys.should include('java.servlet_response')
+ expect(env.keys).to include('rack.version')
+ expect(env.keys).to include('rack.input')
+ expect(env.keys).to include('rack.errors')
+ expect(env.keys).to include('rack.url_scheme')
+ expect(env.keys).to include('rack.multithread')
+ expect(env.keys).to include('rack.run_once')
+ expect(env.keys).to include('java.servlet_context')
+ expect(env.keys).to include('java.servlet_request')
+ expect(env.keys).to include('java.servlet_response')
Rack::Handler::Servlet::DefaultEnv::VARIABLES.each do |key|
- env.keys.should include(key)
+ expect(env.keys).to include(key)
end
- env.keys.should include('HTTP_X_FORWARDED_PROTO')
- env.keys.should include('HTTP_IF_NONE_MATCH')
- env.keys.should include('HTTP_IF_MODIFIED_SINCE')
- env.keys.should include('HTTP_X_SOME_REALLY_LONG_HEADER')
+ expect(env.keys).to include('HTTP_X_FORWARDED_PROTO')
+ expect(env.keys).to include('HTTP_IF_NONE_MATCH')
+ expect(env.keys).to include('HTTP_IF_MODIFIED_SINCE')
+ expect(env.keys).to include('HTTP_X_SOME_REALLY_LONG_HEADER')
end
end
@@ -882,33 +890,33 @@ def servlet.create_env(servlet_env)
it "returns the servlet context when queried with java.servlet_context" do
env = servlet.create_env @servlet_env
- expect( env['java.servlet_context'] ).to_not be nil
+ expect(env['java.servlet_context']).to_not be nil
if servlet_30?
- expect( env['java.servlet_context'] ).to be @servlet_context
+ expect(env['java.servlet_context']).to be @servlet_context
else
- expect( env['java.servlet_context'] ).to be @rack_context
+ expect(env['java.servlet_context']).to be @rack_context
# HACK to emulate Servlet API 3.0 MockHttpServletRequest has getServletContext :
env = Rack::Handler::Servlet::DefaultEnv.new(@servlet_request).to_hash
- expect( env['java.servlet_context'] ).to_not be nil
- expect( env['java.servlet_context'] ).to be @servlet_context
+ expect(env['java.servlet_context']).to_not be nil
+ expect(env['java.servlet_context']).to be @servlet_context
begin
- env['java.servlet_context'].should == @servlet_context
+ expect(env['java.servlet_context']).to eq @servlet_context
rescue NoMethodError
- (env['java.servlet_context'] == @servlet_context).should == true
+ expect((env['java.servlet_context'] == @servlet_context)).to eq true
end
end
end
it "returns the servlet request when queried with java.servlet_request" do
env = servlet.create_env @servlet_env
- expect( env['java.servlet_request'] ).to be @servlet_request
+ expect(env['java.servlet_request']).to be @servlet_request
end
it "returns the servlet response when queried with java.servlet_response" do
env = servlet.create_env @servlet_env
- expect( env['java.servlet_response'] ).to be @servlet_response
+ expect(env['java.servlet_response']).to be @servlet_response
end
end
@@ -916,13 +924,13 @@ def servlet.create_env(servlet_env)
describe "call" do
it "delegates to the inner application after constructing the env hash" do
- servlet.should_receive(:create_env).and_return({})
+ expect(servlet).to receive(:create_env).and_return({})
servlet_env = double("servlet request")
response = servlet.call(servlet_env)
- expect( response.to_java ).to respond_to(:respond) # RackResponse
+ expect(response.to_java).to respond_to(:respond) # RackResponse
- expect( app._called? ).to be true
+ expect(app._called?).to be true
end
it "raises an error when it failed to load the application" do
@@ -942,11 +950,11 @@ def servlet.create_env(servlet_env)
end
it "uses custom response class" do
- servlet.should_receive(:create_env).and_return({})
- #app.should_receive(:call).and_return([ 200, {}, '' ])
+ expect(servlet).to receive(:create_env).and_return({})
+ # expect(app).to receive(:call).and_return([ 200, {}, '' ])
servlet_env = double("servlet request")
- expect( servlet.call(servlet_env) ).to be_a Rack::Handler::CustomResponse
+ expect(servlet.call(servlet_env)).to be_a Rack::Handler::CustomResponse
end
end
@@ -1005,20 +1013,18 @@ def servlet.create_env(servlet_env)
env = servlet.create_env(servlet_env)
rack_request = Rack::Request.new(env)
- rack_request.GET.should == { 'foo'=>'bar', 'bar'=>'huu', 'age'=>'33' }
- rack_request.POST.should == { "name"=>["Ferko Suska", "Jozko Hruska"], "age"=>"30", "formula"=>"a + b == 42%!" }
- rack_request.params.should == {
- "foo"=>"bar", "bar"=>"huu", "age"=>"30",
- "name"=>["Ferko Suska", "Jozko Hruska"], "formula"=>"a + b == 42%!"
- }
-
- #request.body.should == nil
+ expect(rack_request.GET).to eq({ 'foo' => 'bar', 'bar' => 'huu', 'age' => '33' })
+ expect(rack_request.POST).to eq({ "name" => ["Ferko Suska", "Jozko Hruska"], "age" => "30", "formula" => "a + b == 42%!" })
+ expect(rack_request.params).to eq({
+ "foo" => "bar", "bar" => "huu", "age" => "30",
+ "name" => ["Ferko Suska", "Jozko Hruska"], "formula" => "a + b == 42%!"
+ })
- rack_request.query_string.should == 'foo=bad&foo=bar&bar=huu&age=33'
- rack_request.request_method.should == 'POST'
- rack_request.path_info.should == '/path'
- rack_request.script_name.should == '/home' # context path
- rack_request.content_length.should == content.size.to_s
+ expect(rack_request.query_string).to eq 'foo=bad&foo=bar&bar=huu&age=33'
+ expect(rack_request.request_method).to eq 'POST'
+ expect(rack_request.path_info).to eq '/path'
+ expect(rack_request.script_name).to eq '/home' # context path
+ expect(rack_request.content_length).to eq content.size.to_s
end
it "handles null values in parameter-map (Jetty)" do
@@ -1048,7 +1054,7 @@ def servlet.create_env(servlet_env)
servlet_request.addParameter('foo', 'bar')
servlet_request.addParameter('foo', 'huu')
servlet_request.parameters.put('bar', nil) # "emulate" buggy servlet container
- servlet_request.parameters.put('age', [ nil ].to_java(:string)) # buggy container
+ servlet_request.parameters.put('age', [nil].to_java(:string)) # buggy container
# POST params :
servlet_request.addParameter('name[]', 'ferko')
servlet_request.addParameter('name[]', 'jozko')
@@ -1056,14 +1062,14 @@ def servlet.create_env(servlet_env)
env = servlet.create_env(servlet_env)
rack_request = Rack::Request.new(env)
- rack_request.GET.should == { 'foo'=>'huu', 'bar'=>'', 'age'=>'' }
- rack_request.POST.should == { "name"=>["ferko", "jozko"] }
- rack_request.params.should == {
- "foo"=>"huu", "bar"=>"", "age"=>"", "name"=>["ferko", "jozko"],
- }
+ expect(rack_request.GET).to eq({ 'foo' => 'huu', 'bar' => '', 'age' => '' })
+ expect(rack_request.POST).to eq({ "name" => ["ferko", "jozko"] })
+ expect(rack_request.params).to eq({
+ "foo" => "huu", "bar" => "", "age" => "", "name" => ["ferko", "jozko"],
+ })
- rack_request.query_string.should == 'foo=bar&foo=huu&bar=&age='
- rack_request.request_method.should == 'PUT'
+ expect(rack_request.query_string).to eq 'foo=bar&foo=huu&bar=&age='
+ expect(rack_request.request_method).to eq 'PUT'
end
it "does not truncate query strings containing semi-colons (Rack-compat)" do
@@ -1079,11 +1085,11 @@ def servlet.create_env(servlet_env)
env = servlet.create_env(servlet_env)
rack_request = Rack::Request.new(env)
- rack_request.GET.should == { "foo" => "bar", "quux" => "b;la" }
- rack_request.POST.should == {}
- rack_request.params.should == { "foo" => "bar", "quux" => "b;la" }
+ expect(rack_request.GET).to eq({ "foo" => "bar", "quux" => "b;la" })
+ expect(rack_request.POST).to eq({})
+ expect(rack_request.params).to eq({ "foo" => "bar", "quux" => "b;la" })
- rack_request.query_string.should == 'foo=bar&quux=b;la'
+ expect(rack_request.query_string).to eq 'foo=bar&quux=b;la'
end
it "sets cookies from servlet requests" do
@@ -1093,19 +1099,19 @@ def servlet.create_env(servlet_env)
servlet_request.setCookies cookies.to_java :'javax.servlet.http.Cookie'
env = servlet.create_env(servlet_env)
rack_request = Rack::Request.new(env)
- rack_request.cookies.should == { 'foo' => 'bar', 'bar' => '142' }
+ expect(rack_request.cookies).to eq({ 'foo' => 'bar', 'bar' => '142' })
end
it "sets cookies from servlet requests (when empty)" do
- servlet_request.getCookies.should be nil
+ expect(servlet_request.getCookies).to be nil
env = servlet.create_env(servlet_env)
rack_request = Rack::Request.new(env)
- rack_request.cookies.should == {}
+ expect(rack_request.cookies).to eq({})
servlet_request.setCookies [].to_java :'javax.servlet.http.Cookie'
env = servlet.create_env(servlet_env)
rack_request = Rack::Request.new(env)
- rack_request.cookies.should == {}
+ expect(rack_request.cookies).to eq({})
end
it "sets a single cookie from servlet requests" do
@@ -1115,7 +1121,7 @@ def servlet.create_env(servlet_env)
servlet_request.setCookies cookies.to_java :'javax.servlet.http.Cookie'
env = servlet.create_env(servlet_env)
rack_request = Rack::Request.new(env)
- rack_request.cookies.should == { 'foo' => 'bar' }
+ expect(rack_request.cookies).to eq({ 'foo' => 'bar' })
end
private
diff --git a/src/spec/ruby/rack/input_spec.rb b/src/spec/ruby/rack/input_spec.rb
index caffad9c6..c132cbab1 100644
--- a/src/spec/ruby/rack/input_spec.rb
+++ b/src/spec/ruby/rack/input_spec.rb
@@ -18,49 +18,49 @@ module SpecMethods
def it_should_behave_like_rack_input
it "should respond to gets and return a line" do
- input.gets.should == "hello\r\n"
- input.gets.should == "goodbye"
+ expect(input.gets).to eq "hello\r\n"
+ expect(input.gets).to eq "goodbye"
end
it "should return nil for gets at EOF" do
2.times { input.gets }
- input.gets.should == nil
+ expect(input.gets).to eq nil
end
it "should respond to read" do
- input.read.should == "hello\r\ngoodbye"
+ expect(input.read).to eq "hello\r\ngoodbye"
end
it "should read a specified length" do
- input.read(5).should == "hello"
+ expect(input.read(5)).to eq "hello"
end
it "should read its full lenght" do
- input.read(16).should == "hello\r\ngoodbye"
+ expect(input.read(16)).to eq "hello\r\ngoodbye"
end
it "should read into a provided buffer" do
buf = ""
input.read(nil, buf)
- buf.should == "hello\r\ngoodbye"
+ expect(buf).to eq "hello\r\ngoodbye"
end
it "should read a specified amount into a provided buffer" do
buf = ""
input.read(5, buf)
- buf.should == "hello"
+ expect(buf).to eq "hello"
end
it "should replace contents of buffer" do
buf = "cruft"
input.read(5, buf)
- buf.should == "hello"
+ expect(buf).to eq "hello"
end
it "should respond to each and yield lines" do
lines = []
- input.each {|l| lines << l}
- lines.should == ["hello\r\n", "goodbye"]
+ input.each { |l| lines << l }
+ expect(lines).to eq ["hello\r\n", "goodbye"]
end
end
@@ -71,9 +71,9 @@ def it_should_behave_like_rewindable_rack_input
it "should respond to rewind" do
input.read
- input.read.should == ""
+ expect(input.read).to eq ""
input.rewind
- input.read.should == "hello\r\ngoodbye"
+ expect(input.read).to eq "hello\r\ngoodbye"
end
end
@@ -114,36 +114,36 @@ def rewindable_input(buffer_size = nil, max_buffer_size = nil)
buf = ""
input.read(nil, buf)
- buf.size.should == file.length
+ expect(buf.size).to eq file.length
file.seek(0)
- buf.each_byte { |b| b.should == file.read }
+ buf.each_byte { |b| expect(b).to eq file.read }
input.rewind
file.seek(0)
buf = input.read(1000)
- buf.size.should == 1000
- buf.each_byte { |b| b.should == file.read }
+ expect(buf.size).to eq 1000
+ buf.each_byte { |b| expect(b).to eq file.read }
buf = input.read(2000)
- buf.size.should == 2000
- buf.each_byte { |b| b.should == file.read }
+ expect(buf.size).to eq 2000
+ buf.each_byte { |b| expect(b).to eq file.read }
buf = input.read(2000)
- buf.size.should == 1278
- buf.each_byte { |b| b.should == file.read }
+ expect(buf.size).to eq 1278
+ buf.each_byte { |b| expect(b).to eq file.read }
- 10.times { input.read(2000).should be nil }
+ 10.times { expect(input.read(2000)).to be nil }
input.rewind
file.seek(0)
buf = input.read
- buf.size.should == 4278
- buf.each_byte { |b| b.should == file.read }
+ expect(buf.size).to eq 4278
+ buf.each_byte { |b| expect(b).to eq file.read }
- 10.times { input.read.should == '' }
+ 10.times { expect(input.read).to eq '' }
end
it "fully reads an image" do
@@ -154,8 +154,8 @@ def rewindable_input(buffer_size = nil, max_buffer_size = nil)
input = self.input
buf = input.read(file.length)
- buf.size.should == 4278
- buf.each_byte { |b| b.should == file.read }
+ expect(buf.size).to eq 4278
+ buf.each_byte { |b| expect(b).to eq file.read }
end
end
@@ -177,26 +177,26 @@ def rewindable_input(buffer_size = nil, max_buffer_size = nil)
let(:input) { JRuby::Rack::Input.new(rewindable_input(4, 16)) }
it "should be kind and rewind" do
- input.read.should == @content
- input.read.should == ""
+ expect(input.read).to eq @content
+ expect(input.read).to eq ""
input.rewind
- input.read.should == @content
+ expect(input.read).to eq @content
end
it "should be kind and rewind before read" do
input.rewind
- input.read.should == @content
+ expect(input.read).to eq @content
end
it "should be kind and rewind when gets some" do
- input.gets.should == "1\n"
- input.gets.should == " 2\n"
+ expect(input.gets).to eq "1\n"
+ expect(input.gets).to eq " 2\n"
input.rewind
- input.gets.should == "1\n"
- input.gets.should == " 2\n"
- input.gets.should == " 3\n"
- input.gets.should == " 4\n"
- input.read.should == " 5\r\t\n 6\n 7\n 8\n 9\n"
+ expect(input.gets).to eq "1\n"
+ expect(input.gets).to eq " 2\n"
+ expect(input.gets).to eq " 3\n"
+ expect(input.gets).to eq " 4\n"
+ expect(input.read).to eq " 5\r\t\n 6\n 7\n 8\n 9\n"
end
end
@@ -210,7 +210,7 @@ def rewindable_input(buffer_size = nil, max_buffer_size = nil)
end
it "is exposed as JRuby::RackInput (backwards compat)" do
- expect( JRuby::RackInput ).to be JRuby::Rack::Input
+ expect(JRuby::RackInput).to be JRuby::Rack::Input
end
end
diff --git a/src/spec/ruby/rack/servlet/request_capture_spec.rb b/src/spec/ruby/rack/servlet/request_capture_spec.rb
index b587894ef..438a19373 100644
--- a/src/spec/ruby/rack/servlet/request_capture_spec.rb
+++ b/src/spec/ruby/rack/servlet/request_capture_spec.rb
@@ -17,10 +17,10 @@
# See: https://github.com/jruby/jruby-rack/issues/44
it "falls back to requestMap when the reader body has been pre-parsed" do
servlet_request.content_type = "application/x-www-form-urlencoded"
- servlet_request.parameters = {'foo' => 'bar'}
+ servlet_request.parameters = { 'foo' => 'bar' }
servlet_request.content = ''.to_java_bytes
- request_capture.get_parameter('foo').should == 'bar'
+ expect(request_capture.get_parameter('foo')).to eq 'bar'
end
it "reports if input-stream has been accessed" do
@@ -28,10 +28,10 @@
servlet_request.content = '42'.to_java_bytes
request_capture = RequestCapture.new(servlet_request)
- request_capture.isInputAccessed.should == false
+ expect(request_capture.isInputAccessed).to eq false
request_capture.getInputStream
- request_capture.isInputAccessed.should == true
+ expect(request_capture.isInputAccessed).to eq true
end
it "reports if reader has been accessed" do
@@ -39,10 +39,10 @@
servlet_request.content = '42'.to_java_bytes
request_capture = RequestCapture.new(servlet_request)
- request_capture.isInputAccessed.should == false
+ expect(request_capture.isInputAccessed).to eq false
request_capture.getReader
- request_capture.isInputAccessed.should == true
+ expect(request_capture.isInputAccessed).to eq true
end
end
diff --git a/src/spec/ruby/rack/servlet/response_capture_spec.rb b/src/spec/ruby/rack/servlet/response_capture_spec.rb
index b106b9b94..eef2b6b47 100644
--- a/src/spec/ruby/rack/servlet/response_capture_spec.rb
+++ b/src/spec/ruby/rack/servlet/response_capture_spec.rb
@@ -12,57 +12,57 @@
let(:servlet_request) { MockHttpServletRequest.new(@servlet_context) }
it "reports if output (stream) has been accessed" do
- expect( response_capture.isOutputAccessed ).to be false
+ expect(response_capture.isOutputAccessed).to be false
response_capture.getOutputStream
- expect( response_capture.isOutputAccessed ).to be true
+ expect(response_capture.isOutputAccessed).to be true
end
it "reports if output (writer) has been accessed" do
response_capture.getWriter
- expect( response_capture.isOutputAccessed ).to be true
+ expect(response_capture.isOutputAccessed).to be true
end
it "is considered handled by default" do
# NOTE: weird but this is what some containers need to e.g. serve
# static content with RackFilter correctly (e.g. Jetty)
- expect( response_capture.isHandled ).to be true
+ expect(response_capture.isHandled).to be true
end
it "is not considered handled by default or when 404 set" do
- #expect( response_capture.isHandled ).to be false
+ # expect(response_capture.isHandled).to be false
response_capture.setStatus(404)
- expect( response_capture.isHandled ).to be false
+ expect(response_capture.isHandled).to be false
servlet_request.method = 'OPTIONS'
- expect( response_capture.isHandled(servlet_request) ).to be false
+ expect(response_capture.isHandled(servlet_request)).to be false
end
it "is considered handled when 200 status is set" do
response_capture.setStatus(200)
- expect( response_capture.isHandled ).to be true
+ expect(response_capture.isHandled).to be true
end
it "once considered handled stays handled" do
response_capture.setStatus(200)
- expect( response_capture.isHandled ).to be true
+ expect(response_capture.isHandled).to be true
# NOTE: quite important since container might have accessed and written to
# the real output-stream already ... status change should not happen though
response_capture.setStatus(404)
- expect( response_capture.isHandled ).to be true
+ expect(response_capture.isHandled).to be true
end
it "is not considered handled when only Allow header is added with OPTIONS" do
servlet_request.method = 'OPTIONS'
- #expect( response_capture.isHandled(servlet_request) ).to be false
+ # expect(response_capture.isHandled(servlet_request)).to be false
# NOTE: this is what TC's DefaultServlet does on doOptions() :
response_capture.addHeader "Allow", "GET, POST, OPTIONS"
- expect( response_capture.isHandled(servlet_request) ).to be false
+ expect(response_capture.isHandled(servlet_request)).to be false
end
it "is not considered handled when only Allow or Date header is added with OPTIONS" do
@@ -72,7 +72,7 @@
response_capture.addHeader "Allow", "GET, POST, OPTIONS"
response_capture.addHeader "Date", Time.now.httpdate
- expect( response_capture.isHandled(servlet_request) ).to be false
+ expect(response_capture.isHandled(servlet_request)).to be false
end
it "is considered handled when more than Allow header is added with OPTIONS" do
@@ -83,7 +83,7 @@
response_capture.setIntHeader "Answer", 42
response_capture.setHeader "Allow", "GET, POST"
- expect( response_capture.isHandled(servlet_request) ).to be true
+ expect(response_capture.isHandled(servlet_request)).to be true
end
it "is considered handled when header is added" do
@@ -93,14 +93,14 @@
response_capture.addHeader "Hello", "World"
- expect( response_capture.isHandled(servlet_request) ).to be true
- expect( response_capture.getStatus ).to eql 200
+ expect(response_capture.isHandled(servlet_request)).to be true
+ expect(response_capture.getStatus).to eql 200
end
it "is considered handled when a header is set" do
response_capture.setIntHeader "Timeout", 42
- expect( response_capture.isHandled ).to be true
- expect( response_capture.getStatus ).to eql 200
+ expect(response_capture.isHandled).to be true
+ expect(response_capture.getStatus).to eql 200
end
end
diff --git a/src/spec/ruby/rack/servlet/rewindable_input_stream_spec.rb b/src/spec/ruby/rack/servlet/rewindable_input_stream_spec.rb
index bcf484ef3..5fbc7db6a 100644
--- a/src/spec/ruby/rack/servlet/rewindable_input_stream_spec.rb
+++ b/src/spec/ruby/rack/servlet/rewindable_input_stream_spec.rb
@@ -13,17 +13,13 @@
input = []; 49.times { |i| input << i }
stream = rewindable_input_stream(input.to_java(:byte), 6, 24)
- 49.times do |i|
- stream.read.should == i
- end
- 3.times { stream.read.should == -1 }
+ 49.times { |i| expect(stream.read).to eq i }
+ 3.times { expect(stream.read).to eq -1 }
stream.rewind
- 49.times do |i|
- stream.read.should == i
- end
- 2.times { stream.read.should == -1 }
+ 49.times { |i| expect(stream.read).to eq i }
+ 2.times { expect(stream.read).to eq -1 }
end
it "should read data than rewind and read again (in memory)" do
@@ -47,25 +43,20 @@ def it_should_read_127_bytes(init_size = nil, max_size = nil)
stream = @stream || rewindable_input_stream(input.to_java(:byte), init_size, max_size)
data = new_byte_array(7)
- stream.read(data, 0, 7).should == 7 # read 7 bytes
- 7.times do |i|
- data[i].should == i
- end
+ expect(stream.read(data, 0, 7)).to eq 7 # read 7 bytes
+ 7.times { |i| expect(data[i]).to eq i }
data = new_byte_array(42)
- stream.read(data, 10, 20).should == 20 # read 20 bytes
- 10.times { |i| data[i].should == 0 }
- 20.times do |i|
- data[i + 10].should == i + 7
- end
- 10.times { |i| data[i + 30].should == 0 }
+ expect(stream.read(data, 10, 20)).to eq 20 # read 20 bytes
+ 10.times { |i| expect(data[i]).to eq 0 }
+ 20.times { |i| expect(data[i + 10]).to eq i + 7 }
+
+ 10.times { |i| expect(data[i + 30]).to eq 0 }
data = new_byte_array(200)
- stream.read(data, 0, 200).should == 100 # read 100 bytes
- 100.times do |i|
- data[i].should == i + 20 + 7
- end
- 100.times { |i| data[i + 100].should == 0 }
+ expect(stream.read(data, 0, 200)).to eq 100 # read 100 bytes
+ 100.times { |i| expect(data[i]).to eq i + 20 + 7 }
+ 100.times { |i| expect(data[i + 100]).to eq 0 }
stream
end
@@ -75,32 +66,24 @@ def it_should_read_127_bytes(init_size = nil, max_size = nil)
stream = rewindable_input_stream(input.to_java(:byte), 10, 50)
data = new_byte_array(110)
- stream.read(data, 0, 5).should == 5
- 5.times do |i|
- data[i].should == i
- end
+ expect(stream.read(data, 0, 5)).to eq 5
+ 5.times { |i| expect(data[i]).to eq i }
stream.rewind
- stream.read(data, 5, 88).should == 88
- 88.times do |i|
- data[i + 5].should == i
- end
- stream.read.should == 88
- stream.read.should == 89
+ expect(stream.read(data, 5, 88)).to eq 88
+ 88.times { |i| expect(data[i + 5]).to eq i }
+ expect(stream.read).to eq 88
+ expect(stream.read).to eq 89
stream.rewind
- stream.read(data, 10, 33).should == 33
- 33.times do |i|
- data[i + 10].should == i
- end
+ expect(stream.read(data, 10, 33)).to eq 33
+ 33.times { |i| expect(data[i + 10]).to eq i }
stream.rewind
- stream.read(data, 0, 101).should == 100
- 100.times do |i|
- data[i].should == i
- end
+ expect(stream.read(data, 0, 101)).to eq 100
+ 100.times { |i| expect(data[i]).to eq i }
- stream.read.should == -1
+ expect(stream.read).to eq -1
end
it "should rewind unread data" do
@@ -109,10 +92,8 @@ def it_should_read_127_bytes(init_size = nil, max_size = nil)
stream.rewind
data = new_byte_array(120)
- stream.read(data, 10, 110).should == 100
- 100.times do |i|
- data[i + 10].should == i
- end
+ expect(stream.read(data, 10, 110)).to eq 100
+ 100.times { |i| expect(data[i + 10]).to eq i }
end
it "should mark and reset" do
@@ -120,17 +101,17 @@ def it_should_read_127_bytes(init_size = nil, max_size = nil)
stream = rewindable_input_stream(input.to_java(:byte), 5, 20)
15.times { stream.read }
- stream.markSupported.should == true
+ expect(stream.markSupported).to eq true
stream.mark(50)
- 35.times { |i| stream.read.should == 15 + i }
+ 35.times { |i| expect(stream.read).to eq 15 + i }
stream.reset
- 50.times { |i| stream.read.should == 15 + i }
- 35.times { |i| stream.read.should == 65 + i }
+ 50.times { |i| expect(stream.read).to eq 15 + i }
+ 35.times { |i| expect(stream.read).to eq 65 + i }
- stream.read.should == -1
+ expect(stream.read).to eq -1
end
it "should read an image" do
@@ -144,16 +125,16 @@ def it_should_read_127_bytes(init_size = nil, max_size = nil)
while stream.read != -1
index += 1
end
- index.should == file.length
+ expect(index).to eq file.length
stream.rewind
file.seek(0); index = 0
while (byte = stream.read) != -1
- byte.should == file.read
+ expect(byte).to eq file.read
index += 1
end
- index.should == file.length
+ expect(index).to eq file.length
end
it "should delete the tmp file on close" do
@@ -165,11 +146,11 @@ class RewindableInputStream
stream = rewindable_input_stream(input, 10, 12)
13.times { stream.read }
- stream.bufferFilePath.should_not be nil
- File.exist?(stream.bufferFilePath).should be true
+ expect(stream.bufferFilePath).not_to be nil
+ expect(File.exist?(stream.bufferFilePath)).to be true
stream.close
- File.exist?(stream.bufferFilePath).should be false
+ expect(File.exist?(stream.bufferFilePath)).to be false
end
after :all do
@@ -180,20 +161,20 @@ class RewindableInputStream
private
- def rewindable_input_stream(input, buffer_size = nil, max_buffer_size = nil)
- input = to_input_stream(input) unless input.is_a?(java.io.InputStream)
- buffer_size ||= RewindableInputStream::INI_BUFFER_SIZE
- max_buffer_size ||= RewindableInputStream::MAX_BUFFER_SIZE
- RewindableInputStream.new(input, buffer_size, max_buffer_size)
- end
+ def rewindable_input_stream(input, buffer_size = nil, max_buffer_size = nil)
+ input = to_input_stream(input) unless input.is_a?(java.io.InputStream)
+ buffer_size ||= RewindableInputStream::INI_BUFFER_SIZE
+ max_buffer_size ||= RewindableInputStream::MAX_BUFFER_SIZE
+ RewindableInputStream.new(input, buffer_size, max_buffer_size)
+ end
- def to_input_stream(content = @content)
- bytes = content.respond_to?(:to_java_bytes) ? content.to_java_bytes : content
- java.io.ByteArrayInputStream.new(bytes)
- end
+ def to_input_stream(content = @content)
+ bytes = content.respond_to?(:to_java_bytes) ? content.to_java_bytes : content
+ java.io.ByteArrayInputStream.new(bytes)
+ end
- def new_byte_array(length)
- java.lang.reflect.Array.newInstance(java.lang.Byte::TYPE, length)
- end
+ def new_byte_array(length)
+ java.lang.reflect.Array.newInstance(java.lang.Byte::TYPE, length)
+ end
end
\ No newline at end of file
diff --git a/src/spec/ruby/rack/servlet_context_listener_spec.rb b/src/spec/ruby/rack/servlet_context_listener_spec.rb
index b2df1708a..7442eadb9 100644
--- a/src/spec/ruby/rack/servlet_context_listener_spec.rb
+++ b/src/spec/ruby/rack/servlet_context_listener_spec.rb
@@ -5,7 +5,7 @@
RackServletContextListener = org.jruby.rack.RackServletContextListener
before(:each) do
- @servlet_context.stub(:getInitParameter).and_return nil
+ allow(@servlet_context).to receive(:getInitParameter).and_return nil
@factory = double "application factory"
# @listener = RackServletContextListener.new(@factory) :
application_factory = org.jruby.rack.RackApplicationFactory
@@ -22,20 +22,20 @@
describe "contextInitialized" do
it "creates a Rack application factory and store it in the context" do
- @servlet_context.should_receive(:setAttribute).with(RackApplicationFactory::FACTORY, @factory)
- @servlet_context.should_receive(:setAttribute).with(RackApplicationFactory::RACK_CONTEXT, anything())
- @factory.stub(:init)
+ expect(@servlet_context).to receive(:setAttribute).with(RackApplicationFactory::FACTORY, @factory)
+ expect(@servlet_context).to receive(:setAttribute).with(RackApplicationFactory::RACK_CONTEXT, anything())
+ allow(@factory).to receive(:init)
@listener.contextInitialized servlet_context_event
end
it "initializes the application factory" do
- @factory.should_receive(:init)
+ expect(@factory).to receive(:init)
@listener.contextInitialized servlet_context_event
end
it "throws an error if initialization failed" do
@servlet_context = org.springframework.mock.web.MockServletContext.new
- @factory.should_receive(:init).and_raise org.jruby.rack.RackInitializationException.new("help")
+ expect(@factory).to receive(:init).and_raise org.jruby.rack.RackInitializationException.new("help")
expect { @listener.contextInitialized(servlet_context_event) }.to raise_error(org.jruby.rack.RackInitializationException)
end
@@ -43,7 +43,7 @@
it "does not throw if initialization failed (and jruby.rack.error = true)" do
@servlet_context = org.springframework.mock.web.MockServletContext.new
@servlet_context.addInitParameter 'jruby.rack.error', 'true'
- @factory.should_receive(:init).and_raise org.jruby.rack.RackInitializationException.new("help")
+ expect(@factory).to receive(:init).and_raise org.jruby.rack.RackInitializationException.new("help")
expect { @listener.contextInitialized(servlet_context_event) }.to_not raise_error
end
@@ -53,26 +53,26 @@
describe "contextDestroyed" do
it "removes the application factory from the servlet context" do
- @servlet_context.should_receive(:getAttribute).with(
+ expect(@servlet_context).to receive(:getAttribute).with(
org.jruby.rack.RackApplicationFactory::FACTORY).and_return @factory
- @servlet_context.should_receive(:removeAttribute).with(
+ expect(@servlet_context).to receive(:removeAttribute).with(
org.jruby.rack.RackApplicationFactory::FACTORY)
- @servlet_context.should_receive(:removeAttribute).with(
+ expect(@servlet_context).to receive(:removeAttribute).with(
org.jruby.rack.RackApplicationFactory::RACK_CONTEXT)
- @factory.stub(:destroy)
+ allow(@factory).to receive(:destroy)
@listener.contextDestroyed servlet_context_event
end
it "destroys the application factory" do
- @servlet_context.should_receive(:getAttribute).with(
+ expect(@servlet_context).to receive(:getAttribute).with(
org.jruby.rack.RackApplicationFactory::FACTORY).and_return @factory
- @servlet_context.stub(:removeAttribute)
- @factory.should_receive(:destroy)
+ allow(@servlet_context).to receive(:removeAttribute)
+ expect(@factory).to receive(:destroy)
@listener.contextDestroyed servlet_context_event
end
it "does nothing if no application is found in the context" do
- @servlet_context.should_receive(:getAttribute).with(
+ expect(@servlet_context).to receive(:getAttribute).with(
org.jruby.rack.RackApplicationFactory::FACTORY).and_return nil
@listener.contextDestroyed servlet_context_event
end
@@ -80,27 +80,27 @@
end
it "has a default constructor (for servlet container)" do
- lambda { RackServletContextListener.new }.should_not raise_error
+ expect { RackServletContextListener.new }.not_to raise_error
end
it "pools runtimes when max > 1" do
- @rack_config.stub(:getMaximumRuntimes).and_return(2)
+ allow(@rack_config).to receive(:getMaximumRuntimes).and_return(2)
factory = RackServletContextListener.new.
send(:newApplicationFactory, @rack_config)
- factory.should be_a(org.jruby.rack.PoolingRackApplicationFactory)
+ expect(factory).to be_a(org.jruby.rack.PoolingRackApplicationFactory)
end
it "does not pool when max = 1" do
- @rack_config.stub(:getMaximumRuntimes).and_return(1)
+ allow(@rack_config).to receive(:getMaximumRuntimes).and_return(1)
factory = RackServletContextListener.new.
send(:newApplicationFactory, @rack_config)
- factory.should be_a(org.jruby.rack.SharedRackApplicationFactory)
+ expect(factory).to be_a(org.jruby.rack.SharedRackApplicationFactory)
end
it "does not pool by default" do
factory = RackServletContextListener.new.
send(:newApplicationFactory, @rack_config)
- factory.should be_a(org.jruby.rack.SharedRackApplicationFactory)
+ expect(factory).to be_a(org.jruby.rack.SharedRackApplicationFactory)
end
end
@@ -110,35 +110,35 @@
RailsServletContextListener = org.jruby.rack.rails.RailsServletContextListener
it "has a default constructor (for servlet container)" do
- lambda { RailsServletContextListener.new }.should_not raise_error
+ expect { RailsServletContextListener.new }.not_to raise_error
end
it "shares a runtime by default" do
factory = RailsServletContextListener.new.
send(:newApplicationFactory, @rack_config)
- factory.should be_a(org.jruby.rack.SharedRackApplicationFactory)
+ expect(factory).to be_a(org.jruby.rack.SharedRackApplicationFactory)
end
it "pools runtimes when max > 1" do
- @rack_config.stub(:getMaximumRuntimes).and_return(2)
+ allow(@rack_config).to receive(:getMaximumRuntimes).and_return(2)
factory = RailsServletContextListener.new.
send(:newApplicationFactory, @rack_config)
- factory.should be_a(org.jruby.rack.PoolingRackApplicationFactory)
+ expect(factory).to be_a(org.jruby.rack.PoolingRackApplicationFactory)
end
it "pools runtimes when max > 1 and serial initialization" do
- @rack_config.stub(:getMaximumRuntimes).and_return(3)
- @rack_config.stub(:isSerialInitialization).and_return(true)
+ allow(@rack_config).to receive(:getMaximumRuntimes).and_return(3)
+ allow(@rack_config).to receive(:isSerialInitialization).and_return(true)
factory = RailsServletContextListener.new.
send(:newApplicationFactory, @rack_config)
- factory.should be_a(org.jruby.rack.SerialPoolingRackApplicationFactory)
+ expect(factory).to be_a(org.jruby.rack.SerialPoolingRackApplicationFactory)
end
it "does not pool when max = 1" do
- @rack_config.stub(:getMaximumRuntimes).and_return(1)
+ allow(@rack_config).to receive(:getMaximumRuntimes).and_return(1)
factory = RailsServletContextListener.new.
send(:newApplicationFactory, @rack_config)
- factory.should be_a(org.jruby.rack.SharedRackApplicationFactory)
+ expect(factory).to be_a(org.jruby.rack.SharedRackApplicationFactory)
end
end
diff --git a/src/spec/ruby/rack/servlet_spec.rb b/src/spec/ruby/rack/servlet_spec.rb
index 8b0f7cd3a..082325806 100644
--- a/src/spec/ruby/rack/servlet_spec.rb
+++ b/src/spec/ruby/rack/servlet_spec.rb
@@ -13,20 +13,20 @@
request = javax.servlet.http.HttpServletRequest.impl {}
response = javax.servlet.http.HttpServletResponse.impl {}
dispatcher = double "dispatcher"
- dispatcher.should_receive(:process)
+ expect(dispatcher).to receive(:process)
servlet = org.jruby.rack.RackServlet.new dispatcher, @rack_context
servlet.service request, response
end
it "should destroy dispatcher on destroy" do
dispatcher = double "dispatcher"
- dispatcher.should_receive(:destroy)
+ expect(dispatcher).to receive(:destroy)
servlet = org.jruby.rack.RackServlet.new dispatcher, @rack_context
servlet.destroy
end
it "should have default constructor (for servlet container)" do
- lambda { org.jruby.rack.RackServlet.new }.should_not raise_error
+ expect { org.jruby.rack.RackServlet.new }.not_to raise_error
end
end
@@ -35,30 +35,28 @@
before :each do
rack_config = org.jruby.rack.servlet.ServletRackConfig.new(@servlet_context)
- @context = org.jruby.rack.servlet.DefaultServletRackContext.new(rack_config)
+ @context = org.jruby.rack.servlet.DefaultServletRackContext.new(rack_config)
end
it "should use getResource when getRealPath returns nil" do
- @servlet_context.stub(:getRealPath).and_return nil
+ allow(@servlet_context).to receive(:getRealPath).and_return nil
url = java.net.URL.new("file:///var/tmp/foo.txt")
- @servlet_context.should_receive(:getResource).with("/WEB-INF").and_return url
- @context.getRealPath("/WEB-INF").should == "/var/tmp/foo.txt"
+ expect(@servlet_context).to receive(:getResource).with("/WEB-INF").and_return url
+ expect(@context.getRealPath("/WEB-INF")).to eq "/var/tmp/foo.txt"
end
it "should strip file: prefix for getRealPath" do
- @servlet_context.stub(:getRealPath).and_return nil
+ allow(@servlet_context).to receive(:getRealPath).and_return nil
# we're emulating a ServletContext.getResource returning an URL which might
# differ for different containers - WLS 10 might behave this way from time:
url = java.net.URL.new 'file', nil, 0, "file:/foo/bar", nil
- # url.path.should == "file:/foo/bar"
- @servlet_context.should_receive(:getResource).with("/bar").and_return url
- @context.getRealPath("/bar").should == "/foo/bar"
+ expect(@servlet_context).to receive(:getResource).with("/bar").and_return url
+ expect(@context.getRealPath("/bar")).to eq "/foo/bar"
url = java.net.URL.new 'file', nil, 0, "file:///foo/bar", nil
- # url.path.should == "file:///foo/bar"
- @servlet_context.should_receive(:getResource).with("/bar").and_return url
- @context.getRealPath("/bar").should == "/foo/bar"
+ expect(@servlet_context).to receive(:getResource).with("/bar").and_return url
+ expect(@context.getRealPath("/bar")).to eq "/foo/bar"
end
end
diff --git a/src/spec/ruby/rack/tag_spec.rb b/src/spec/ruby/rack/tag_spec.rb
index 704a63038..337952e64 100644
--- a/src/spec/ruby/rack/tag_spec.rb
+++ b/src/spec/ruby/rack/tag_spec.rb
@@ -17,19 +17,19 @@ def call(request)
before :each do
@result = double("Rack Result")
- @result.stub(:getBody).and_return("Hello World!")
+ allow(@result).to receive(:getBody).and_return("Hello World!")
@application = double("application")
- @application.stub(:call).and_return @result
+ allow(@application).to receive(:call).and_return @result
@rack_factory = org.jruby.rack.RackApplicationFactory.impl {}
- @rack_factory.stub(:getApplication).and_return @application
- @rack_factory.stub(:finishedWithApplication)
+ allow(@rack_factory).to receive(:getApplication).and_return @application
+ allow(@rack_factory).to receive(:finishedWithApplication)
- @servlet_context.stub(:getAttribute).with('rack.factory').and_return @rack_factory
- @servlet_context.stub(:getAttribute).with('rack.context').and_return @rack_context
+ allow(@servlet_context).to receive(:getAttribute).with('rack.factory').and_return @rack_factory
+ allow(@servlet_context).to receive(:getAttribute).with('rack.context').and_return @rack_context
@servlet_request = double("Servlet Request")
- @servlet_request.stub(:getContextPath).and_return ""
+ allow(@servlet_request).to receive(:getContextPath).and_return ""
@servlet_response = double("Servlet Response")
@writable = org.jruby.rack.fake.FakeJspWriter.new
@@ -46,35 +46,35 @@ def call(request)
end
it 'should get an application and return it to the pool' do
- @rack_factory.should_receive(:getApplication).and_return @application
- @rack_factory.should_receive(:finishedWithApplication)
+ expect(@rack_factory).to receive(:getApplication).and_return @application
+ expect(@rack_factory).to receive(:finishedWithApplication)
@tag.doEndTag
end
it 'should return the application to the pool even when an exception is thrown' do
- @rack_factory.should_receive(:getApplication).and_return ExceptionThrower.new
- @rack_factory.should_receive(:finishedWithApplication)
+ expect(@rack_factory).to receive(:getApplication).and_return ExceptionThrower.new
+ expect(@rack_factory).to receive(:finishedWithApplication)
begin
@tag.doEndTag
rescue Java::JavaxServletJsp::JspException
- #noop
+ # noop
end
end
it 'should create a request wrapper and invoke the application' do
- @application.should_receive(:call).and_return @result
+ expect(@application).to receive(:call).and_return @result
@tag.doEndTag
end
it 'should override the path, query params, and http method of the request' do
- @application.should_receive(:call) do |wrapped_request|
- wrapped_request.servlet_path.should == ""
- wrapped_request.path_info.should == '/controller/action/id'
- wrapped_request.query_string.should == 'fruit=apple&horse_before=cart'
- wrapped_request.request_uri.should == '/controller/action/id?fruit=apple&horse_before=cart'
- wrapped_request.method.should == 'GET'
+ expect(@application).to receive(:call) do |wrapped_request|
+ expect(wrapped_request.servlet_path).to eq ""
+ expect(wrapped_request.path_info).to eq '/controller/action/id'
+ expect(wrapped_request.query_string).to eq 'fruit=apple&horse_before=cart'
+ expect(wrapped_request.request_uri).to eq '/controller/action/id?fruit=apple&horse_before=cart'
+ expect(wrapped_request.method).to eq 'GET'
@result
end
@@ -83,6 +83,6 @@ def call(request)
it 'should write the response back to the page' do
@tag.doEndTag
- @writable.to_s.should == 'Hello World!'
+ expect(@writable.to_s).to eq 'Hello World!'
end
end
diff --git a/src/spec/ruby/rack/util_spec.rb b/src/spec/ruby/rack/util_spec.rb
index 732fc4492..778d205aa 100644
--- a/src/spec/ruby/rack/util_spec.rb
+++ b/src/spec/ruby/rack/util_spec.rb
@@ -7,51 +7,40 @@
require File.expand_path('spec_helper', File.dirname(__FILE__) + '/..')
describe org.jruby.rack.util.IOHelpers do
-
+
IOHelpers = org.jruby.rack.util.IOHelpers
-
+
it "reads a stream into a string" do
code = "# comment\n" +
- "puts 'vůl or kôň';\n" +
- "exit(0)\n"
+ "puts 'vůl or kôň';\n" +
+ "exit(0)\n"
stream = java.io.ByteArrayInputStream.new code.to_java.getBytes('UTF-8')
stream = java.io.BufferedInputStream.new(stream, 8)
string = IOHelpers.inputStreamToString(stream)
- expect( string ).to eql "# comment\nputs 'vůl or kôň';\nexit(0)\n"
+ expect(string).to eql "# comment\nputs 'vůl or kôň';\nexit(0)\n"
end
-# it "reads a stream into a string with encoding comment" do
-# code = "# encoding: ISO-8859-1\n" +
-# "# another comment \n" +
-# "puts 'vůl or kôň';\n"
-# #"puts 'v\xC5\xAFl or k\xC3\xB4\xC5\x88';\n"
-# bytes = java.lang.String.new(code.to_java.getBytes, "UTF-8").getBytes("ISO-8859-1")
-# stream = java.io.ByteArrayInputStream.new bytes
-# string = IOHelpers.inputStreamToString(stream)
-# expect( string ).to eql "# encoding: ISO-8859-1\n# another comment \nputs 'vůl or kôň';\n"
-# end
-
it "reads magic comment 1" do
code = "# hello: world \n" +
- "# comment\n" +
- "exit(0);"
+ "# comment\n" +
+ "exit(0);"
string = IOHelpers.rubyMagicCommentValue(code, "hello:")
- expect( string ).to eql "world"
+ expect(string).to eql "world"
end
it "reads magic comment 2" do
code = "# encoding: UTF-8 \n" +
- "# comment\n" +
- "# rack.version: 1.3.6 \n" +
- "exit(0)\n'42'"
+ "# comment\n" +
+ "# rack.version: 1.3.6 \n" +
+ "exit(0)\n'42'"
string = IOHelpers.rubyMagicCommentValue(code, "rack.version:")
- expect( string ).to eql "1.3.6"
+ expect(string).to eql "1.3.6"
end
-
+
it "works when reading an empty/null string" do
- expect( IOHelpers.rubyMagicCommentValue(nil, 'ruby.version:') ).to be nil
- expect( IOHelpers.rubyMagicCommentValue('', 'ruby.version:') ).to be nil
- expect( IOHelpers.rubyMagicCommentValue("\n", 'ruby.version:') ).to be nil
+ expect(IOHelpers.rubyMagicCommentValue(nil, 'ruby.version:')).to be nil
+ expect(IOHelpers.rubyMagicCommentValue('', 'ruby.version:')).to be nil
+ expect(IOHelpers.rubyMagicCommentValue("\n", 'ruby.version:')).to be nil
end
-
+
end
\ No newline at end of file
diff --git a/src/spec/ruby/spec_helper.rb b/src/spec/ruby/spec_helper.rb
index fd9c8dbb4..56d17736c 100644
--- a/src/spec/ruby/spec_helper.rb
+++ b/src/spec/ruby/spec_helper.rb
@@ -1,6 +1,6 @@
target = File.expand_path('target', "#{File.dirname(__FILE__)}/../../..")
-jars = File.exist?(lib = "#{target}/lib") && ( Dir.entries(lib) - [ '.', '..' ] )
-raise "missing .jar dependencies please run `rake test_prepare'" if ! jars || jars.empty?
+jars = File.exist?(lib = "#{target}/lib") && (Dir.entries(lib) - ['.', '..'])
+raise "missing .jar dependencies please run `rake test_prepare'" if !jars || jars.empty?
$CLASSPATH << File.expand_path('classes', target)
$CLASSPATH << File.expand_path('test-classes', target)
jars.each { |jar| $CLASSPATH << File.expand_path(jar, lib) }
@@ -31,22 +31,24 @@ def mock_servlet_context
@servlet_context = ServletContext.impl {}
@rack_config ||= RackConfig.impl {}
@rack_context ||= ServletRackContext.impl {}
- [ @rack_context, @servlet_context ].each do |context|
- context.stub(:log)
- context.stub(:isEnabled).and_return nil
- context.stub(:getInitParameter).and_return nil
- context.stub(:getRealPath).and_return "/"
- context.stub(:getResource).and_return nil
- context.stub(:getContextPath).and_return "/"
+ [@rack_context, @servlet_context].each do |context|
+ allow(context).to receive(:log)
+ allow(context).to receive(:isEnabled).and_return nil
+ allow(context).to receive(:getInitParameter).and_return nil
+ allow(context).to receive(:getRealPath).and_return "/"
+ allow(context).to receive(:getResource).and_return nil
+ allow(context).to receive(:getContextPath).and_return "/"
end
- @rack_context.stub(:getConfig).and_return @rack_config
+ allow(@rack_context).to receive(:getConfig).and_return @rack_config
@servlet_config ||= ServletConfig.impl {}
- @servlet_config.stub(:getServletName).and_return "a Servlet"
- @servlet_config.stub(:getServletContext).and_return @servlet_context
+ allow(@servlet_config).to receive(:getServletName).and_return "a Servlet"
+ allow(@servlet_config).to receive(:getServletContext).and_return @servlet_context
@servlet_context
end
- def servlet_context; mock_servlet_context end
+ def servlet_context
+ mock_servlet_context
+ end
def silence_warnings(&block)
JRuby::Rack::Helpers.silence_warnings(&block)
@@ -56,14 +58,16 @@ def silence_warnings(&block)
def servlet_30?
return @@servlet_30 unless @@servlet_30.nil?
- @@servlet_30 = !! ( Java::javax.servlet.AsyncContext rescue nil )
+ @@servlet_30 = !!(Java::javax.servlet.AsyncContext rescue nil)
end
+
private :servlet_30?
def rack_release_at_least?(at_least = nil)
require 'rack';
at_least ? Rack.release >= at_least : true
end
+
private :rack_release_at_least?
def raise_logger(level = 'WARN')
@@ -104,7 +108,7 @@ def expect_eql_java_bytes(actual, expected)
if expected[i] != actual[i]
raise ExpectationNotMetError, "byte[] arrays differ at #{i}"
end
- break if ( i += 1 ) >= expected.length
+ break if (i += 1) >= expected.length
end
end
@@ -121,26 +125,28 @@ def should_eval_as_eql_to(code, expected, options = {})
expected = expected.inspect.to_java
actual = runtime.evalScriptlet(code).inspect.to_java
- actual.equals(expected).should be_flag, message.gsub('$expected', expected.to_s).gsub('$actual', actual.to_s)
+ expect(actual.equals(expected)).to be_flag, message.gsub('$expected', expected.to_s).gsub('$actual', actual.to_s)
end
def should_eval_as_not_eql_to(code, expected, options = {})
- should_eval_as_eql_to(code, expected, options.merge(:should => be_falsy,
- :message => options[:message] || "expected eval #{code.inspect} to be != $expected but was not")
+ should_eval_as_eql_to(code, expected, options.merge(
+ :should => be_falsy,
+ :message => options[:message] || "expected eval #{code.inspect} to be != $expected but was not")
)
end
def should_eval_as_nil(code, runtime = @runtime)
should_eval_as_eql_to code, nil, :runtime => runtime,
- :message => "expected eval #{code.inspect} to be nil but was $actual"
+ :message => "expected eval #{code.inspect} to be nil but was $actual"
end
def should_eval_as_not_nil(code, runtime = @runtime)
should_eval_as_eql_to code, nil, :should => be_falsy, :runtime => runtime,
- :message => "expected eval #{code.inspect} to not be nil but was"
+ :message => "expected eval #{code.inspect} to not be nil but was"
end
- def should_not_eval_as_nil(code, runtime = @runtime) # alias
+ def should_not_eval_as_nil(code, runtime = @runtime)
+ # alias
should_eval_as_not_nil(code, runtime)
end
@@ -179,8 +185,8 @@ def should_not_eval_as_nil(code, runtime = @runtime) # alias
end
config.after(:each) do
- (ENV.keys - @env_save.keys).each {|k| ENV.delete k}
- @env_save.each {|k,v| ENV[k] = v}
+ (ENV.keys - @env_save.keys).each { |k| ENV.delete k }
+ @env_save.each { |k, v| ENV[k] = v }
Dir.chdir(WD_START) unless Dir.getwd == WD_START
$servlet_context = nil if defined? $servlet_context
end