spec/integration/rack_app/middleware_spec.rb in hanami-2.0.0.beta3 vs spec/integration/rack_app/middleware_spec.rb in hanami-2.0.0.beta4

- old
+ new

@@ -204,6 +204,34 @@ get "/" expect(last_response).to be_successful expect(last_response.body).to eql("yes") end + + context "Using module as a middleware" do + it "sets the module as the middleware" do + mod = Module.new + app = Class.new(Hanami::App) { config.middleware.use(mod) } + + expect(app.config.middleware.stack["/"][0]).to include(mod) + end + end + + context "Setting an unsupported middleware" do + it "raises meaningful error when an unsupported middleware spec was passed" do + expect { + Class.new(Hanami::App) do + config.middleware.use("oops") + end + }.to raise_error(Hanami::UnsupportedMiddlewareSpecError) + end + + it "raises meaningful error when corresponding file failed to load" do + expect { + Class.new(Hanami::App) do + config.middleware.namespaces.delete(Hanami::Middleware) + config.middleware.use(:body_parser) + end + }.to raise_error(Hanami::UnsupportedMiddlewareSpecError) + end + end end