From f2ac0fb8b3f258004b451599271164cdd7a9ff48 Mon Sep 17 00:00:00 2001 From: Chad Wilson Date: Sat, 22 Jun 2024 16:39:10 +0800 Subject: [PATCH] Correct rspec expectations Signed-off-by: Chad Wilson --- .../session/java_servlet_store_spec.rb | 44 ++++++------ .../cgi/session/java_servlet_store_spec.rb | 2 +- src/spec/ruby/jruby/rack/helpers_spec.rb | 6 +- src/spec/ruby/jruby/rack/queues_spec.rb | 10 +-- src/spec/ruby/jruby/rack/response_spec.rb | 14 ++-- src/spec/ruby/rack/application_spec.rb | 68 +++++++++---------- src/spec/ruby/rack/dispatcher_spec.rb | 4 +- src/spec/ruby/rack/filter_spec.rb | 50 +++++++------- src/spec/ruby/rack/handler/servlet_spec.rb | 34 +++++----- .../rack/servlet_context_listener_spec.rb | 4 +- src/spec/ruby/rack/tag_spec.rb | 2 +- src/spec/ruby/spec_helper.rb | 6 +- 12 files changed, 117 insertions(+), 127 deletions(-) diff --git a/src/spec/ruby/action_controller/session/java_servlet_store_spec.rb b/src/spec/ruby/action_controller/session/java_servlet_store_spec.rb index 832cd711..caa804c3 100644 --- a/src/spec/ruby/action_controller/session/java_servlet_store_spec.rb +++ b/src/spec/ruby/action_controller/session/java_servlet_store_spec.rb @@ -33,7 +33,7 @@ end it "should raise an error if the servlet request is not present" do - lambda { @session_store.call({}) }.should raise_error + expect { @session_store.call({}) }.to raise_error(RuntimeError) end it "should do nothing if the session is not accessed" do @@ -57,7 +57,7 @@ it "should load the session when accessed" do @request.should_receive(:getSession).with(false).and_return @session @session.stub(:setAttribute); @session.stub(:getCreationTime).and_return 1 - @app.should_receive(:call).and_return do |env| + @app.should_receive(:call) do |env| env['rack.session']['foo'] end @session_store.call(@env) @@ -73,7 +73,7 @@ it "should report session loaded when accessed" do @request.should_receive(:getSession).with(false).and_return @session @session.stub(:setAttribute); @session.stub(:getCreationTime).and_return 1 - @app.should_receive(:call).and_return do |env| + @app.should_receive(:call) do |env| env['rack.session']['foo'] end @session_store.call(@env) @@ -84,7 +84,7 @@ it "should use custom session hash when loading session" do @request.should_receive(:getSession).with(false).and_return @session @session.stub(:setAttribute); @session.stub(:getCreationTime).and_return 1 - @app.should_receive(:call).and_return do |env| + @app.should_receive(:call) do |env| env['rack.session']["foo"] = "bar" end @session_store.call(@env) @@ -106,7 +106,7 @@ @session.should_receive(:getAttributeNames).and_return [session_key] @session.should_receive(:getAttribute).with(session_key).and_return marshal_data.to_java_bytes @session.stub(:setAttribute); @session.stub(:getCreationTime).and_return 1 - @app.should_receive(:call).and_return do |env| + @app.should_receive(:call) do |env| env['rack.session']["foo"].should == 1 env['rack.session']["bar"].should == true end @@ -120,7 +120,7 @@ @session.should_receive(:getAttribute).with("foo").and_return hash["foo"] @session.should_receive(:getAttribute).with("bar").and_return hash["bar"] @session.stub(:setAttribute); @session.stub(:getCreationTime).and_return 1 - @app.should_receive(:call).and_return do |env| + @app.should_receive(:call) do |env| env['rack.session']["foo"].should == hash["foo"] env['rack.session']["bar"].should == hash["bar"] end @@ -132,7 +132,7 @@ @session.should_receive(:getAttributeNames).and_return ["foo"] @session.should_receive(:getAttribute).with("foo").and_return java.lang.Object.new @session.stub(:setAttribute); @session.stub(:getCreationTime).and_return 1 - @app.should_receive(:call).and_return do |env| + @app.should_receive(:call) do |env| env['rack.session']["foo"].should be_kind_of(java.lang.Object) end @session_store.call(@env) @@ -143,7 +143,7 @@ @session.stub(:getAttribute).and_return nil; @session.stub(:getCreationTime).and_return 1 @session.should_receive(:setAttribute).with(ActionController::Session::JavaServletStore::RAILS_SESSION_KEY, an_instance_of(Java::byte[])) - @app.should_receive(:call).and_return do |env| + @app.should_receive(:call) do |env| env['rack.session']['foo'] = Object.new end @session_store.call(@env) @@ -154,7 +154,7 @@ @request.should_receive(:getSession).with(true).ordered.and_return @session @session.should_receive(:setAttribute).with(ActionController::Session::JavaServletStore::RAILS_SESSION_KEY, an_instance_of(Java::byte[])) - @app.should_receive(:call).and_return do |env| + @app.should_receive(:call) do |env| env['rack.session']['foo'] = Object.new end @session_store.call(@env) @@ -164,7 +164,7 @@ @request.should_receive(:getSession).with(false).and_return @session @session.stub(:setAttribute); @session.stub(:getCreationTime).and_return 1 @session.should_receive(:setAttribute).with("foo", "bar") - @app.should_receive(:call).and_return do |env| + @app.should_receive(:call) do |env| env['rack.session']["foo"] = "bar" end @session_store.call(@env) @@ -176,7 +176,7 @@ @session.should_receive(:setAttribute).with("foo", true) @session.should_receive(:setAttribute).with("bar", 20) @session.should_receive(:setAttribute).with("baz", false) - @app.should_receive(:call).and_return do |env| + @app.should_receive(:call) do |env| env['rack.session']["foo"] = true env['rack.session']["bar"] = 20 env['rack.session']["baz"] = false @@ -188,7 +188,7 @@ @request.should_receive(:getSession).with(false).and_return @session @session.stub(:setAttribute); @session.stub(:getCreationTime).and_return 1 @session.should_receive(:setAttribute).with("foo", an_instance_of(java.lang.Object)) - @app.should_receive(:call).and_return do |env| + @app.should_receive(:call) do |env| env['rack.session']["foo"] = java.lang.Object.new end @session_store.call(@env) @@ -200,7 +200,7 @@ @session.stub(:setAttribute); @session.stub(:getCreationTime).and_return 1 @session.should_receive(:removeAttribute).with("foo") @session.should_receive(:removeAttribute).with("baz") - @app.should_receive(:call).and_return do |env| + @app.should_receive(:call) do |env| env['rack.session'].delete('foo') env['rack.session']['baz'] = nil env['rack.session']['bar'] = 'x' @@ -212,7 +212,7 @@ @request.should_receive(:getSession).with(false).and_return @session @session.stub(:getId).and_return(nil) @session.should_receive(:invalidate).ordered - @app.should_receive(:call).and_return do |env| + @app.should_receive(:call) do |env| env['rack.session.options'].delete(:id) #env['rack.session'] = new_session_hash(env) env['rack.session'].send :load! @@ -224,11 +224,11 @@ session = double_http_session(nil); session.invalidate @request.should_receive(:getSession).with(false).and_return session - @app.should_receive(:call).and_return do |env| + @app.should_receive(:call) do |env| env['rack.session.options'].delete(:id) env['rack.session'].send :load! end - expect( lambda { @session_store.call(@env) } ).to_not raise_error + expect { @session_store.call(@env) }.to_not raise_error end it "should handle session with an invalid servlet session" do @@ -240,7 +240,7 @@ @request.should_receive(:getSession).ordered. with(true).and_return new_session = double_http_session - @app.should_receive(:call).and_return do |env| + @app.should_receive(:call) do |env| env['rack.session']['foo'] = 'bar' end @session_store.call(@env) @@ -248,7 +248,7 @@ it "should do nothing on session reset if no session is established" do @request.should_receive(:getSession).with(false).and_return nil - @app.should_receive(:call).and_return do |env| + @app.should_receive(:call) do |env| env['rack.session.options'].delete(:id) env['rack.session'] = new_session_hash(env) # not loaded? end @@ -260,7 +260,7 @@ @request.should_receive(:getSession).and_return @session @session.should_receive(:getLastAccessedTime).and_return time @session.stub(:setAttribute) - @app.should_receive(:call).and_return do |env| + @app.should_receive(:call) do |env| env['rack.session'].getLastAccessedTime.should == time lambda { env['rack.session'].blah_blah }.should raise_error(NoMethodError) end @@ -274,7 +274,7 @@ new_session = double_http_session @request.should_receive(:getSession).ordered.with(true).and_return(new_session) - @app.should_receive(:call).and_return do |env| + @app.should_receive(:call) do |env| env['rack.session.options'] = { :id => sid, :renew => true, :defer => true } env['rack.session']['_csrf_token'] = 'v3PrzsdkWug9Q3xCthKkEzUMbZSzgQ9Bt+43lH0bEF8=' end @@ -292,11 +292,11 @@ it "handles the skip session option" do @request.should_receive(:getSession).with(false).and_return @session @session.should_not_receive(:setAttribute) - @app.should_receive(:call).and_return do |env| + @app.should_receive(:call) do |env| env['rack.session.options'][:skip] = true env['rack.session']['foo'] = 'bar' end - expect( lambda { @session_store.call(@env) } ).to_not raise_error + expect { @session_store.call(@env) }.to_not raise_error end private diff --git a/src/spec/ruby/cgi/session/java_servlet_store_spec.rb b/src/spec/ruby/cgi/session/java_servlet_store_spec.rb index 602dbb2a..7a936950 100644 --- a/src/spec/ruby/cgi/session/java_servlet_store_spec.rb +++ b/src/spec/ruby/cgi/session/java_servlet_store_spec.rb @@ -24,7 +24,7 @@ def session_store it "should raise an error if the servlet request is not present" do @options.delete("java_servlet_request") - lambda { session_store }.should raise_error + expect { session_store }.to raise_error(RuntimeError) end describe "#restore" do diff --git a/src/spec/ruby/jruby/rack/helpers_spec.rb b/src/spec/ruby/jruby/rack/helpers_spec.rb index a2525358..1332e285 100644 --- a/src/spec/ruby/jruby/rack/helpers_spec.rb +++ b/src/spec/ruby/jruby/rack/helpers_spec.rb @@ -44,7 +44,7 @@ class SomeKlass < Object end it "constantizes strictly" do - expect( lambda { constantize('Some', A::B) } ).to raise_error(NameError) + expect { constantize('Some', A::B) }.to raise_error(NameError) end it "constantizes non-stricly from Object (parent) context" do @@ -95,8 +95,8 @@ class SomeKlass < Object it "resolves a constant" do expect( resolve_constant("JRuby::Rack::Helpers::Some") ).to be_a Class - expect( lambda { resolve_constant("JRuby::Rack::Helpers::Missing") }).to raise_error NameError - expect( lambda { resolve_constant("JRuby::Rack::Helpers::Another") }).to raise_error NameError + 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/queues_spec.rb b/src/spec/ruby/jruby/rack/queues_spec.rb index 55a775c3..857b0afc 100644 --- a/src/spec/ruby/jruby/rack/queues_spec.rb +++ b/src/spec/ruby/jruby/rack/queues_spec.rb @@ -108,11 +108,11 @@ def mock_message(text) @registry.register_listener "FooQ", listener @queue_manager.should_receive(:close).with "FooQ" @registry.unregister_listener(listener) - lambda { @registry.receive_message("FooQ", mock_message("msg")) }.should raise_error + lambda { @registry.receive_message("FooQ", mock_message("msg")) }.should raise_error(RuntimeError) end it "#receive_message should raise an exception if there is no listener for the queue" do - lambda { @registry.receive_message("NoQ", "hi") }.should raise_error + lambda { @registry.receive_message("NoQ", "hi") }.should raise_error(RuntimeError) end it "#register_listener should allow multiple listeners per queue" do @@ -175,7 +175,7 @@ def mock_message(text) it "should unmarshal the message if the marshal payload property is set" do @message.should_receive(:getBooleanProperty).with(JRuby::Rack::Queues::MARSHAL_PAYLOAD).and_return true first = false - @message.should_receive(:readBytes).twice.and_return do |byte_array| + @message.should_receive(:readBytes).twice do |byte_array| if first -1 else @@ -233,13 +233,13 @@ def on_message(msg) @servlet_context.should_receive(:log).with(/something went wrong/) lambda do JRuby::Rack::Queues::MessageDispatcher.new(@listener).dispatch(@message) - end.should raise_error + end.should raise_error(RuntimeError) end it "should raise an exception if it was unable to dispatch to anything" do @message.stub(:getBooleanProperty).and_return false lambda do JRuby::Rack::Queues::MessageDispatcher.new(@listener).dispatch(@message) - end.should raise_error + end.should raise_error(RuntimeError) end end diff --git a/src/spec/ruby/jruby/rack/response_spec.rb b/src/spec/ruby/jruby/rack/response_spec.rb index 521154d0..c9338230 100644 --- a/src/spec/ruby/jruby/rack/response_spec.rb +++ b/src/spec/ruby/jruby/rack/response_spec.rb @@ -181,7 +181,7 @@ class << value; undef_method :each; end if value.respond_to?(:each) response.write_headers(response_environment) times = 0 - stream.should_receive(:write).exactly(6).times.with do |bytes| + stream.should_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 @@ -223,7 +223,7 @@ class << value; undef_method :each; end if value.respond_to?(:each) response.write_headers(response_environment) times = 0 - stream.should_receive(:write).exactly(3).times.with do |bytes| + stream.should_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" @@ -258,7 +258,7 @@ class << value; undef_method :each; end if value.respond_to?(:each) response.write_headers(response_environment) times = 0 - stream.should_receive(:write).exactly(5).times.with do |bytes| + stream.should_receive(:write).exactly(5).times do |bytes| str = String.from_java_bytes(bytes) case times += 1 when 1 then str.should == "1" @@ -404,7 +404,7 @@ def wrap_file_body(path) # Rails style when doing #send_file path = File.expand_path('../../files/image.jpg', File.dirname(__FILE__)) response = JRuby::Rack::Response.new [ 200, {}, FileBody.new(path) ] - response.should_receive(:send_file).with do |path, response| + response.should_receive(:send_file) do |path, response| expect( path ).to eql path expect( response).to be response_environment end @@ -526,13 +526,13 @@ def with_swallow_client_abort(client_abort = true) private - def update_response_headers(headers, response) + def update_response_headers(headers) response.to_java.getHeaders.update(headers) end - def new_response_environment(servlet_response) + def new_response_environment(this_servlet_response = servlet_response) org.jruby.rack.RackResponseEnvironment.impl do |name, *args| - servlet_response.send(name, *args) + this_servlet_response.send(name, *args) end end diff --git a/src/spec/ruby/rack/application_spec.rb b/src/spec/ruby/rack/application_spec.rb index 5edc8e07..0955abb9 100644 --- a/src/spec/ruby/rack/application_spec.rb +++ b/src/spec/ruby/rack/application_spec.rb @@ -26,7 +26,7 @@ let(:servlet_context) do servlet_context = double("servlet_context") - servlet_context.stub(:getInitParameter).and_return do |name| + servlet_context.stub(:getInitParameter) do |name| name && nil # return null end servlet_context @@ -182,7 +182,7 @@ def createRackServletWrapper(runtime, rackup); end @app_factory.init @rack_context @app_factory.rackup_script.should == nil - @rack_context.should_receive(:log).with do |*args| + @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/ end @@ -221,7 +221,7 @@ def newRuntime() # use the current runtime instead of creating new @rack_context.stub(:getInitParameter).and_return nil @rack_context.stub(:getResourcePaths).and_return nil @rack_context.stub(:getRealPath) { |path| path } - #@rack_context.stub(:log).with do |*args| + #@rack_context.stub(:log) do |*args| #puts args.inspect #end end @@ -311,10 +311,10 @@ def newRuntime() # use the current runtime instead of creating new end it "loads specified version of rack", :lib => :stub do - gem_install_unless_installed 'rack', '1.3.10' + gem_install_unless_installed 'rack', '2.1.4' set_config 'jruby.runtime.env', 'false' - script = "# rack.version: ~>1.3.6\n Proc.new { 'proc-rack-app' }" + script = "# rack.version: ~>2.1.0\n Proc.new { 'proc-rack-app' }" app_factory.setRackupScript script @runtime = app_factory.newRuntime @runtime.evalScriptlet "ENV['GEM_HOME'] = #{ENV['GEM_HOME'].inspect}" @@ -323,8 +323,8 @@ def newRuntime() # use the current runtime instead of creating new app_factory.checkAndSetRackVersion(@runtime) @runtime.evalScriptlet "require 'rack'" - should_eval_as_eql_to "Rack.release if defined? Rack.release", '1.3' - should_eval_as_eql_to "Gem.loaded_specs['rack'].version.to_s", '1.3.10' + should_eval_as_eql_to "Rack.release if defined? Rack.release", '2.1' + should_eval_as_eql_to "Gem.loaded_specs['rack'].version.to_s", '2.1.4' end it "loads bundler with rack", :lib => :stub do @@ -462,14 +462,14 @@ def newRuntime() # use the current runtime instead of creating new set_config 'jruby.compat.version', '1.9' #@rack_config.stub(:getCompatVersion).and_return org.jruby.CompatVersion::RUBY1_9 @runtime = app_factory.new_runtime - @runtime.is1_9.should be_true + @runtime.is1_9.should be_truthy end 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) @runtime = app_factory.new_runtime - @runtime.object_space_enabled.should be_true + @runtime.object_space_enabled.should be_truthy @runtime.kcode.should == Java::OrgJrubyUtil::KCode::EUC end @@ -688,7 +688,7 @@ def createRackServletWrapper(runtime, rackup); end it "creates applications during initialization according to the jruby.min.runtimes context parameter" do @factory.stub(:init) - @factory.stub(:newApplication).and_return do + @factory.stub(:newApplication) do app = double "app" app.should_receive(:init) app @@ -721,7 +721,7 @@ def createRackServletWrapper(runtime, rackup); end it "forces the maximum size to be greater or equal to the initial size" do @factory.stub(:init) - @factory.stub(:newApplication).and_return do + @factory.stub(:newApplication) do app = double "app" app.should_receive(:init) app @@ -743,9 +743,9 @@ def createRackServletWrapper(runtime, rackup); end it "waits till initial runtimes get initialized (with wait set to true)" do @factory.stub(:init) - @factory.stub(:newApplication).and_return do + @factory.stub(:newApplication) do app = double "app" - app.stub(:init).and_return do + app.stub(:init) do sleep(0.10) end app @@ -762,9 +762,9 @@ def createRackServletWrapper(runtime, rackup); end "(even when only a single application initialization fails)" do @factory.stub(:init) app_count = java.util.concurrent.atomic.AtomicInteger.new(0) - @factory.stub(:newApplication).and_return do + @factory.stub(:newApplication) do app = double "app" - app.stub(:init).and_return do + app.stub(:init) do if app_count.addAndGet(1) == 2 raise org.jruby.rack.RackInitializationException.new('failed app init') end @@ -794,9 +794,9 @@ def createRackServletWrapper(runtime, rackup); end it "wait until pool is filled when invoking getApplication (with wait set to false)" do @factory.stub(:init) - @factory.stub(:newApplication).and_return do + @factory.stub(:newApplication) do app = double "app" - app.stub(:init).and_return { sleep(0.2) } + app.stub(:init) { sleep(0.2) } app end @rack_config.stub(:getBooleanProperty).with("jruby.runtime.init.wait").and_return false @@ -812,9 +812,9 @@ def createRackServletWrapper(runtime, rackup); end it "waits acquire timeout till an application is available from the pool (than raises)" do @factory.stub(:init) - @factory.should_receive(:newApplication).twice.and_return do + @factory.should_receive(:newApplication).twice do app = double "app" - app.should_receive(:init).and_return { sleep(0.2) } + app.should_receive(:init) { sleep(0.2) } app end @rack_config.stub(:getBooleanProperty).with("jruby.runtime.init.wait").and_return false @@ -842,9 +842,9 @@ def createRackServletWrapper(runtime, rackup); end it "gets and initializes new applications until maximum allows to create more" do @factory.stub(:init) - @factory.should_receive(:newApplication).twice.and_return do + @factory.should_receive(:newApplication).twice do app = double "app (new)" - app.should_receive(:init).and_return { sleep(0.1) } + app.should_receive(:init) { sleep(0.1) } app end @rack_config.stub(:getBooleanProperty).with("jruby.runtime.init.wait").and_return false @@ -858,7 +858,7 @@ def createRackServletWrapper(runtime, rackup); end 2.times { @pooling_factory.getApplication.should_not be nil } }.should_not raise_error - @factory.should_receive(:getApplication).twice.and_return do + @factory.should_receive(:getApplication).twice do app = double "app (get)"; sleep(0.15); app end @@ -879,9 +879,9 @@ def createRackServletWrapper(runtime, rackup); end it "initializes initial runtimes in paralel (with wait set to false)" do @factory.stub(:init) - @factory.stub(:newApplication).and_return do + @factory.stub(:newApplication) do app = double "app" - app.stub(:init).and_return do + app.stub(:init) do sleep(0.15) end app @@ -902,9 +902,9 @@ def createRackServletWrapper(runtime, rackup); end it "throws from init when application initialization in thread failed" do @factory.stub(:init) - @factory.stub(:newApplication).and_return do + @factory.stub(:newApplication) do app = double "app" - app.stub(:init).and_return do + app.stub(:init) do sleep(0.05); raise "app.init raising" end app @@ -913,7 +913,7 @@ def createRackServletWrapper(runtime, rackup); end @rack_config.stub(:getMaximumRuntimes).and_return 2 raise_error_logged = 0 - @rack_context.stub(:log).with do |level, msg, e| + @rack_context.stub(: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 @@ -923,9 +923,7 @@ def createRackServletWrapper(runtime, rackup); end end end - expect(lambda { - @pooling_factory.init(@rack_context) - }).to raise_error org.jruby.rack.RackInitializationException + 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 # NOTE: seems it's not such a good idea to return empty on init error @@ -944,9 +942,9 @@ def createRackServletWrapper(runtime, rackup); end it "initializes initial runtimes in serial order" do @factory.should_receive(:init).with(@rack_context) - @factory.stub(:newApplication).and_return do + @factory.stub(:newApplication) do app = double "app" - app.stub(:init).and_return do + app.stub(:init) do sleep(0.05) end app @@ -981,7 +979,7 @@ def createRackServletWrapper(runtime, rackup); end @factory.should_receive(:init).with(@rack_context) @factory.should_receive(:getApplication).and_raise java.lang.ArithmeticException.new('42') - @rack_context.should_receive(:log).with do |level, msg, e| + @rack_context.should_receive(:log) do |level, msg, e| if level == 'ERROR' expect( e ).to be_a java.lang.ArithmeticException else @@ -1011,9 +1009,7 @@ def createRackServletWrapper(runtime, rackup); end rescue java.lang.RuntimeException => e # NOOP end - expect( lambda { - @shared_factory.getApplication - }).to raise_error(org.jruby.rack.RackInitializationException) + expect { @shared_factory.getApplication }.to raise_error(org.jruby.rack.RackInitializationException) end it "returns the same application for any newApplication or getApplication call" do diff --git a/src/spec/ruby/rack/dispatcher_spec.rb b/src/spec/ruby/rack/dispatcher_spec.rb index edb5897a..05d63756 100644 --- a/src/spec/ruby/rack/dispatcher_spec.rb +++ b/src/spec/ruby/rack/dispatcher_spec.rb @@ -82,9 +82,7 @@ res.stub(:reset) res.should_not_receive(:sendError) - expect( lambda { - @dispatcher.process(req, res) - } ).to raise_error(org.jruby.rack.RackException) + expect { @dispatcher.process(req, res) }.to raise_error(org.jruby.rack.RackException) end end diff --git a/src/spec/ruby/rack/filter_spec.rb b/src/spec/ruby/rack/filter_spec.rb index b310f118..e5a99109 100644 --- a/src/spec/ruby/rack/filter_spec.rb +++ b/src/spec/ruby/rack/filter_spec.rb @@ -39,7 +39,7 @@ def stub_request(path_info) end it "should dispatch the filter chain and finish if the chain resulted in a successful response" do - chain.should_receive(:doFilter).ordered.and_return do |_, resp| + chain.should_receive(:doFilter).ordered do |_, resp| resp.setStatus(200) end @response.should_receive(:setStatus).ordered.with(200) @@ -47,7 +47,7 @@ def stub_request(path_info) end it "should finish if the chain resulted in a redirect" do - chain.should_receive(:doFilter).ordered.and_return do |_, resp| + chain.should_receive(:doFilter).ordered do |_, resp| resp.sendRedirect("/some/url") end @response.should_receive(:sendRedirect).ordered.with("/some/url") @@ -55,7 +55,7 @@ def stub_request(path_info) end it "dispatches to the rack dispatcher if the chain resulted in a 404" do - chain.should_receive(:doFilter).ordered.and_return do |_, resp| + chain.should_receive(:doFilter).ordered do |_, resp| resp.sendError(404) end @response.should_receive(:reset).ordered @@ -67,7 +67,7 @@ def stub_request(path_info) 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.and_return do |_, resp| + chain.should_receive(:doFilter).ordered do |_, resp| resp.sendError(403) end @response.should_receive(:reset).ordered @@ -78,7 +78,7 @@ def stub_request(path_info) 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.and_return do |_, resp| + chain.should_receive(:doFilter).ordered do |_, resp| resp.sendError(405) end @response.should_receive(:reset).ordered @@ -89,7 +89,7 @@ def stub_request(path_info) 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.and_return do |_, resp| + chain.should_receive(:doFilter).ordered do |_, resp| resp.sendError(501) end @response.should_receive(:reset) @@ -106,7 +106,7 @@ def wrapResponse(response) end end.new(dispatcher, @rack_context) - chain.should_receive(:doFilter).ordered.and_return do |_, resp| + chain.should_receive(:doFilter).ordered do |_, resp| resp.sendError(442) end @response.should_receive(:reset).ordered @@ -115,7 +115,7 @@ def wrapResponse(response) end it "allows downstream entities to flush the buffer in the case of a successful response" do - chain.should_receive(:doFilter).ordered.and_return do |_, resp| + chain.should_receive(:doFilter).ordered do |_, resp| resp.setStatus(200) resp.flushBuffer end @@ -126,7 +126,7 @@ def wrapResponse(response) 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.and_return do |_, resp| + chain.should_receive(:doFilter).ordered do |_, resp| resp.sendError(404) resp.flushBuffer end @@ -137,7 +137,7 @@ def wrapResponse(response) end it "only resets the buffer for a 404 if configured so" do - chain.should_receive(:doFilter).ordered.and_return do |_, resp| + chain.should_receive(:doFilter).ordered do |_, resp| resp.sendError(404) resp.flushBuffer end @@ -150,7 +150,7 @@ def wrapResponse(response) end it "allows an error response from the filter chain (and flushes the buffer)" do - chain.should_receive(:doFilter).ordered.and_return do |_, resp| + chain.should_receive(:doFilter).ordered do |_, resp| resp.sendError(401) resp.flushBuffer end @@ -170,7 +170,7 @@ def isHandled(arg); getStatus < 400; end end end.new(dispatcher, @rack_context) - chain.should_receive(:doFilter).ordered.and_return do |_, resp| + chain.should_receive(:doFilter).ordered do |_, resp| resp.sendError(401) resp.flushBuffer end @@ -185,7 +185,7 @@ def isHandled(arg); getStatus < 400; end request.stub(:getPathInfo).and_return path_info request.stub(:getServletPath).and_return "/some/uri" end - chain.should_receive(:doFilter).ordered.and_return do |req,resp| + 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" @@ -196,12 +196,12 @@ def isHandled(arg); getStatus < 400; end end it "should set status to 404 when dispatcher's status is not found" do - chain.should_receive(:doFilter).ordered.and_return do |_, resp| + chain.should_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.and_return do |_, resp| + dispatcher.should_receive(:process).ordered do |_, resp| resp.setStatus(404) end @response.should_receive(:setStatus).ordered.with(404) @@ -216,7 +216,7 @@ def isHandled(arg); getStatus < 400; end it "should dispatch /some/uri/index.html unchanged" do stub_request("/index.html") - chain.should_receive(:doFilter).ordered.and_return do |req,resp| + chain.should_receive(:doFilter).ordered do |req,resp| req.getRequestURI.should == "/some/uri/index.html" resp.setStatus(200) end @@ -226,7 +226,7 @@ def isHandled(arg); getStatus < 400; end it "should convert / to /index.html" do stub_request("/") - chain.should_receive(:doFilter).ordered.and_return do |req,resp| + chain.should_receive(:doFilter).ordered do |req,resp| req.getServletPath.should == "/some/uri/index.html" resp.setStatus(200) end @@ -239,7 +239,7 @@ def isHandled(arg); getStatus < 400; end request.stub(:getPathInfo).and_return nil request.stub(:getServletPath).and_return "/some/uri/index.html" end - chain.should_receive(:doFilter).ordered.and_return do |req,resp| + chain.should_receive(:doFilter).ordered do |req,resp| req.getPathInfo.should == nil req.getServletPath.should == "/some/uri/index.html" req.getRequestURI.should == "/some/uri/" @@ -251,7 +251,7 @@ def isHandled(arg); getStatus < 400; end it "should add .html to the path" do stub_request("") - chain.should_receive(:doFilter).ordered.and_return do |req,resp| + chain.should_receive(:doFilter).ordered do |req,resp| req.getServletPath.should == "/some/uri.html" resp.setStatus(200) end @@ -261,7 +261,7 @@ def isHandled(arg); getStatus < 400; end it "should process dispatching when chain throws a FileNotFoundException (WAS 8.0 behavior)" do stub_request("/foo") - chain.should_receive(:doFilter).ordered.and_return do + chain.should_receive(:doFilter).ordered do raise java.io.FileNotFoundException.new("/foo.html") end dispatcher.should_receive(:process) @@ -277,7 +277,7 @@ def isHandled(arg); getStatus < 400; end end it "dispatches /some/uri/index unchanged" do - chain.should_receive(:doFilter).ordered.and_return do |req,resp| + chain.should_receive(:doFilter).ordered do |req,resp| req.getServletPath.should == "/some/uri/index" req.getRequestURI.should == "/some/uri/index" resp.setStatus(200) @@ -295,7 +295,7 @@ 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.and_return do |req,resp| + chain.should_receive(:doFilter).ordered do |req,resp| req.getRequestURI.should == "/some/uri/index" resp.setStatus(200) end @@ -305,7 +305,7 @@ def isHandled(arg); getStatus < 400; 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.and_return do |req,resp| + chain.should_receive(:doFilter).ordered do |req,resp| req.getRequestURI.should == "/some/uri/index.html" resp.setStatus(200) end @@ -316,7 +316,7 @@ def isHandled(arg); getStatus < 400; 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") stub_request("/") - chain.should_receive(:doFilter).ordered.and_return do |req,resp| + chain.should_receive(:doFilter).ordered do |req,resp| req.getRequestURI.should == "/some/uri/index.html" resp.setStatus(200) end @@ -327,7 +327,7 @@ def isHandled(arg); getStatus < 400; 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") stub_request("") - chain.should_receive(:doFilter).ordered.and_return do |req,resp| + chain.should_receive(:doFilter).ordered do |req,resp| req.getServletPath.should == "/some/uri.html" resp.setStatus(200) end diff --git a/src/spec/ruby/rack/handler/servlet_spec.rb b/src/spec/ruby/rack/handler/servlet_spec.rb index abfbc119..5d3c4f66 100644 --- a/src/spec/ruby/rack/handler/servlet_spec.rb +++ b/src/spec/ruby/rack/handler/servlet_spec.rb @@ -542,44 +542,42 @@ def getAttributeNames env = servlet.create_env filled_servlet_env env.freeze - expect( lambda { env['REQUEST_METHOD'] } ).to_not raise_error - expect( lambda { env['SCRIPT_NAME'] } ).to_not raise_error + expect { env['REQUEST_METHOD'] }.to_not raise_error + expect { env['SCRIPT_NAME'] }.to_not raise_error Rack::Handler::Servlet::DefaultEnv::BUILTINS.each do |key| - expect( lambda { env[key] } ).to_not raise_error + expect { env[key] }.to_not raise_error env[key].should_not be nil end - expect( lambda { env['OTHER_METHOD'] } ).to_not raise_error + expect { env['OTHER_METHOD'] }.to_not raise_error env['OTHER_METHOD'].should be nil - expect( lambda { env['rack.version'] } ).to_not raise_error - expect( lambda { env['rack.input'] } ).to_not raise_error - expect( lambda { env['rack.errors'] } ).to_not raise_error - expect( lambda { env['rack.run_once'] } ).to_not raise_error - expect( lambda { env['rack.multithread'] } ).to_not raise_error - expect( lambda { env['java.servlet_context'] } ).to_not raise_error - expect( lambda { env['java.servlet_request'] } ).to_not raise_error - expect( lambda { env['java.servlet_response'] } ).to_not raise_error + expect { env['rack.version'] }.to_not raise_error + expect { env['rack.input'] }.to_not raise_error + expect { env['rack.errors'] }.to_not raise_error + expect { env['rack.run_once'] }.to_not raise_error + expect { env['rack.multithread'] }.to_not raise_error + expect { env['java.servlet_context'] }.to_not raise_error + 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" end - expect( lambda { env['rack.whatever'] } ).to_not raise_error + expect { env['rack.whatever'] }.to_not raise_error env['rack.whatever'].should be nil - expect( lambda { + expect { env['HTTP_X_FORWARDED_PROTO'] env['HTTP_IF_NONE_MATCH'] env['HTTP_IF_MODIFIED_SINCE'] env['HTTP_X_SOME_REALLY_LONG_HEADER'] - }).to_not raise_error + }.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( lambda { - env['HTTP_X_SOME_NON_EXISTENT_HEADER'] - }).to_not raise_error + expect { env['HTTP_X_SOME_NON_EXISTENT_HEADER'] }.to_not raise_error env['HTTP_X_SOME_NON_EXISTENT_HEADER'].should be nil end diff --git a/src/spec/ruby/rack/servlet_context_listener_spec.rb b/src/spec/ruby/rack/servlet_context_listener_spec.rb index c2cee5cb..9c2a57dc 100644 --- a/src/spec/ruby/rack/servlet_context_listener_spec.rb +++ b/src/spec/ruby/rack/servlet_context_listener_spec.rb @@ -46,9 +46,7 @@ @servlet_context.add_init_parameter 'jruby.rack.error', 'false' @factory.should_receive(:init).and_raise org.jruby.rack.RackInitializationException.new("help") - expect(lambda { - @listener.contextInitialized servlet_context_event - }).to raise_error(org.jruby.rack.RackInitializationException) + expect { @listener.contextInitialized servlet_context_event }.to raise_error(org.jruby.rack.RackInitializationException) end end diff --git a/src/spec/ruby/rack/tag_spec.rb b/src/spec/ruby/rack/tag_spec.rb index 167078e3..704a6303 100644 --- a/src/spec/ruby/rack/tag_spec.rb +++ b/src/spec/ruby/rack/tag_spec.rb @@ -69,7 +69,7 @@ def call(request) end it 'should override the path, query params, and http method of the request' do - @application.should_receive(:call).and_return do |wrapped_request| + @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' diff --git a/src/spec/ruby/spec_helper.rb b/src/spec/ruby/spec_helper.rb index b1650e28..e22de99f 100644 --- a/src/spec/ruby/spec_helper.rb +++ b/src/spec/ruby/spec_helper.rb @@ -138,7 +138,7 @@ def should_eval_as_eql_to(code, expected, options = {}) runtime, options = options, {} end message = options[:message] || "expected eval #{code.inspect} to be == $expected but was $actual" - be_flag = options.has_key?(:should) ? options[:should] : be_true + be_flag = options.has_key?(:should) ? options[:should] : be_truthy expected = expected.inspect.to_java actual = runtime.evalScriptlet(code).inspect.to_java @@ -146,7 +146,7 @@ def should_eval_as_eql_to(code, expected, options = {}) end def should_eval_as_not_eql_to(code, expected, options = {}) - should_eval_as_eql_to(code, expected, options.merge(:should => be_false, + 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 @@ -157,7 +157,7 @@ def should_eval_as_nil(code, runtime = @runtime) end def should_eval_as_not_nil(code, runtime = @runtime) - should_eval_as_eql_to code, nil, :should => be_false, :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" end