From 5d65bcb3b97a8299ca69e5469c77a3626f990efa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Thu, 20 Jul 2017 15:23:32 +0200 Subject: [PATCH] Refactor spec helper classes locations and visibility --- spec/config_spec.cr | 7 +++++++ spec/dsl_helper.cr | 17 ----------------- spec/handler_spec.cr | 10 +++++----- spec/helpers_spec.cr | 12 ++++++------ spec/spec_helper.cr | 17 +++++++++++++++++ 5 files changed, 35 insertions(+), 28 deletions(-) diff --git a/spec/config_spec.cr b/spec/config_spec.cr index f6db81f..b87c93f 100644 --- a/spec/config_spec.cr +++ b/spec/config_spec.cr @@ -1,5 +1,12 @@ require "./spec_helper" +private class CustomTestHandler < Kemal::Handler + def call(env) + env.response << "Kemal" + call_next env + end +end + describe "Config" do it "sets default port to 3000" do config = Kemal::Config.new diff --git a/spec/dsl_helper.cr b/spec/dsl_helper.cr index 5aa05ee..39a4e91 100644 --- a/spec/dsl_helper.cr +++ b/spec/dsl_helper.cr @@ -12,23 +12,6 @@ class CustomLogHandler < Kemal::BaseLogHandler end end -class TestContextStorageType - property id - @id = 1 - - def to_s - @id - end -end - -class AnotherContextStorageType - property name - @name = "kemal-context" -end - -add_context_storage_type(TestContextStorageType) -add_context_storage_type(AnotherContextStorageType) - def create_request_and_return_io(handler, request) io = IO::Memory.new response = HTTP::Server::Response.new(io) diff --git a/spec/handler_spec.cr b/spec/handler_spec.cr index cd2a450..1b48ccc 100644 --- a/spec/handler_spec.cr +++ b/spec/handler_spec.cr @@ -1,13 +1,13 @@ require "./spec_helper" -class CustomTestHandler < Kemal::Handler +private class CustomTestHandler < Kemal::Handler def call(env) env.response << "Kemal" call_next env end end -class OnlyHandler < Kemal::Handler +private class OnlyHandler < Kemal::Handler only ["/only"] def call(env) @@ -17,7 +17,7 @@ class OnlyHandler < Kemal::Handler end end -class ExcludeHandler < Kemal::Handler +private class ExcludeHandler < Kemal::Handler exclude ["/exclude"] def call(env) @@ -27,7 +27,7 @@ class ExcludeHandler < Kemal::Handler end end -class PostOnlyHandler < Kemal::Handler +private class PostOnlyHandler < Kemal::Handler only ["/only", "/route1", "/route2"], "POST" def call(env) @@ -37,7 +37,7 @@ class PostOnlyHandler < Kemal::Handler end end -class PostExcludeHandler < Kemal::Handler +private class PostExcludeHandler < Kemal::Handler exclude ["/exclude"], "POST" def call(env) diff --git a/spec/helpers_spec.cr b/spec/helpers_spec.cr index 4e70bfa..b03cbc9 100644 --- a/spec/helpers_spec.cr +++ b/spec/helpers_spec.cr @@ -1,13 +1,13 @@ require "./spec_helper" -describe "Macros" do - describe "#public_folder" do - it "sets public folder" do - public_folder "/some/path/to/folder" - Kemal.config.public_folder.should eq("/some/path/to/folder") - end +private class CustomTestHandler < Kemal::Handler + def call(env) + env.response << "Kemal" + call_next env end +end +describe "Macros" do describe "#add_handler" do it "adds a custom handler" do app = Kemal::Application.new diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr index bfa50b0..f840b61 100644 --- a/spec/spec_helper.cr +++ b/spec/spec_helper.cr @@ -1,6 +1,23 @@ require "spec" require "../src/kemal" +class TestContextStorageType + property id + @id = 1 + + def to_s + @id + end +end + +class AnotherContextStorageType + property name + @name = "kemal-context" +end + +Kemal::Macros.add_context_storage_type(TestContextStorageType) +Kemal::Macros.add_context_storage_type(AnotherContextStorageType) + def call_request_on_app(app, request) io = IO::Memory.new response = HTTP::Server::Response.new(io)