spec/integration/rack_app/middleware_spec.rb in hanami-2.0.3 vs spec/integration/rack_app/middleware_spec.rb in hanami-2.1.0.beta1

- old
+ new

@@ -242,10 +242,11 @@ require "hanami" module TestApp class App < Hanami::App config.logger.stream = File.new("/dev/null", "w") + config.render_errors = true end end RUBY write "lib/test_app/middleware/authentication.rb", <<~RUBY @@ -314,12 +315,11 @@ end it "excludes not found routes in root scope" do get "/foo" - expect(last_response.status).to eq 404 - expect(last_response.body).to eq "Not Found" + expect(last_response.status).to eq 500 expect(last_response.headers).to_not have_key("X-Auth-User-ID") end context "within slice" do it "uses Rack middleware" do @@ -328,16 +328,15 @@ expect(last_response.status).to eq 200 expect(last_response.body).to eq "Hello from admin (User ID 23)" expect(last_response.headers).to have_key("X-Auth-User-ID") end - it "uses Rack middleware for not found paths" do + it "does not uses the Rack middleware for not found paths" do get "/admin/users" - expect(last_response.status).to be(404) - expect(last_response.body).to eq "Not Found" - expect(last_response.headers).to have_key("X-Auth-User-ID") + expect(last_response.status).to eq 500 + expect(last_response.headers).not_to have_key("X-Auth-User-ID") end end end context "with complex app" do @@ -348,10 +347,11 @@ require "hanami" module TestApp class App < Hanami::App config.logger.stream = File.new("/dev/null", "w") + config.render_errors = true end end RUBY write "lib/test_app/middleware/elapsed.rb", <<~RUBY @@ -595,19 +595,19 @@ expect(last_response.headers).to_not have_key("X-Auth-User-ID") expect(last_response.headers).to_not have_key("X-API-Rate-Limit-Quota") expect(last_response.headers).to_not have_key("X-API-Version") end - it "uses Rack middleware for other paths" do - get "/foo" + it "does not use Rack middleware for other paths" do + get "/__not_found__" - expect(last_response.status).to be(404) - expect(last_response.headers["X-Identifier-Root"]).to eq("true") - expect(last_response.headers).to have_key("X-Elapsed") - expect(last_response.headers).to_not have_key("X-Auth-User-ID") - expect(last_response.headers).to_not have_key("X-API-Rate-Limit-Quota") - expect(last_response.headers).to_not have_key("X-API-Version") + expect(last_response.status).to eq 500 + expect(last_response.headers).not_to have_key("X-Identifier-Root") + expect(last_response.headers).not_to have_key("X-Elapsed") + expect(last_response.headers).not_to have_key("X-Auth-User-ID") + expect(last_response.headers).not_to have_key("X-API-Rate-Limit-Quota") + expect(last_response.headers).not_to have_key("X-API-Version") end context "scoped" do it "uses Rack middleware" do get "/admin" @@ -619,18 +619,18 @@ expect(last_response.headers).to_not have_key("X-API-Rate-Limit-Quota") expect(last_response.headers).to_not have_key("X-API-Version") end it "uses Rack middleware for other paths" do - get "/admin/users" + get "/admin/__not_found__" - expect(last_response.status).to be(404) - expect(last_response.headers["X-Identifier-Admin"]).to eq("true") - expect(last_response.headers).to have_key("X-Elapsed") - expect(last_response.headers).to have_key("X-Elapsed") - expect(last_response.headers).to have_key("X-Auth-User-ID") - expect(last_response.headers).to_not have_key("X-API-Rate-Limit-Quota") - expect(last_response.headers).to_not have_key("X-API-Version") + expect(last_response.status).to eq 500 + expect(last_response.headers).not_to have_key("X-Identifier-Admin") + expect(last_response.headers).not_to have_key("X-Elapsed") + expect(last_response.headers).not_to have_key("X-Elapsed") + expect(last_response.headers).not_to have_key("X-Auth-User-ID") + expect(last_response.headers).not_to have_key("X-API-Rate-Limit-Quota") + expect(last_response.headers).not_to have_key("X-API-Version") end # See: https://github.com/hanami/api/issues/8 it "uses Rack middleware for scope w/o leading slash" do get "/api"