diff --git a/bin/amber_spec b/bin/amber_spec index 7cf8be1bc..222a9d739 100755 --- a/bin/amber_spec +++ b/bin/amber_spec @@ -9,5 +9,5 @@ crystal tool format --check echo "\nRunning 'crystal spec':" crystal spec -#echo "\nRunning 'crystal spec ./spec/build_spec_granite.cr':" -#crystal spec ./spec/build_spec_granite.cr +echo "\nRunning 'crystal spec ./spec/build_spec_granite.cr':" +crystal spec ./spec/build_spec_granite.cr diff --git a/src/amber/cli/templates/api/controller/spec/controllers/spec_helper.cr.ecr b/src/amber/cli/templates/api/controller/spec/controllers/spec_helper.cr.ecr index cba784c4c..d47c991fb 100644 --- a/src/amber/cli/templates/api/controller/spec/controllers/spec_helper.cr.ecr +++ b/src/amber/cli/templates/api/controller/spec/controllers/spec_helper.cr.ecr @@ -1 +1,2 @@ require "../spec_helper" +require "../request_helper" diff --git a/src/amber/cli/templates/api/controller/spec/controllers/{{name}}_controller_spec.cr.ecr b/src/amber/cli/templates/api/controller/spec/controllers/{{name}}_controller_spec.cr.ecr index 3abce197d..9c92838e1 100644 --- a/src/amber/cli/templates/api/controller/spec/controllers/{{name}}_controller_spec.cr.ecr +++ b/src/amber/cli/templates/api/controller/spec/controllers/{{name}}_controller_spec.cr.ecr @@ -25,7 +25,8 @@ def <%= create_model_method %> model end -class <%= class_name %>ControllerTest < GarnetSpec::SystemTest +class <%= class_name %>ControllerTest + include RequestHelper getter handler : Amber::Pipe::Pipeline def initialize diff --git a/src/amber/cli/templates/app/shard.yml.ecr b/src/amber/cli/templates/app/shard.yml.ecr index e2b349fad..39dfc80cb 100644 --- a/src/amber/cli/templates/app/shard.yml.ecr +++ b/src/amber/cli/templates/app/shard.yml.ecr @@ -52,9 +52,6 @@ dependencies: version: ~> 1.0.0 development_dependencies: - garnet_spec: - github: amberframework/garnet-spec - version: 0.4.1 ameba: github: crystal-ameba/ameba version: ~> 0.13.4 diff --git a/src/amber/cli/templates/app/spec/request_helper.cr.ecr b/src/amber/cli/templates/app/spec/request_helper.cr.ecr new file mode 100644 index 000000000..ca67a4bb9 --- /dev/null +++ b/src/amber/cli/templates/app/spec/request_helper.cr.ecr @@ -0,0 +1,30 @@ +require "http" + +module RequestHelper + macro included + {% http_read_verbs = %w(get head options trace connect) %} + {% http_write_verbs = %w(post put patch delete) %} + {% http_verbs = http_read_verbs + http_write_verbs %} + + {% for method in http_verbs %} + def {{method.id}}(path, headers : HTTP::Headers? = nil, body : String? = nil) + request = HTTP::Request.new("{{method.id}}".upcase, path, headers, body ) + {% if http_write_verbs.includes? method %} + request.headers["Content-Type"] ||= "application/x-www-form-urlencoded" + {% end %} + process_request(request) + end + {% end %} + end + + private def process_request(request) + io = IO::Memory.new + response = HTTP::Server::Response.new(io) + context = HTTP::Server::Context.new(request, response) + handler.call context + response.close + io.rewind + client_response = HTTP::Client::Response.from_io(io, decompress: false) + client_response + end +end diff --git a/src/amber/cli/templates/app/spec/spec_helper.cr.ecr b/src/amber/cli/templates/app/spec/spec_helper.cr.ecr index ddf80c3ce..5f3e24578 100644 --- a/src/amber/cli/templates/app/spec/spec_helper.cr.ecr +++ b/src/amber/cli/templates/app/spec/spec_helper.cr.ecr @@ -2,7 +2,6 @@ ENV["AMBER_ENV"] ||= "test" require "spec" require "micrate" -require "garnet_spec" require "../config/application" diff --git a/src/amber/cli/templates/auth/spec/controllers/spec_helper.cr.ecr b/src/amber/cli/templates/auth/spec/controllers/spec_helper.cr.ecr index cba784c4c..d47c991fb 100644 --- a/src/amber/cli/templates/auth/spec/controllers/spec_helper.cr.ecr +++ b/src/amber/cli/templates/auth/spec/controllers/spec_helper.cr.ecr @@ -1 +1,2 @@ require "../spec_helper" +require "../request_helper" diff --git a/src/amber/cli/templates/channel/src/channels/{{name}}_channel.cr.ecr b/src/amber/cli/templates/channel/src/channels/{{name}}_channel.cr.ecr index 18ec7050b..5d79d75dc 100644 --- a/src/amber/cli/templates/channel/src/channels/{{name}}_channel.cr.ecr +++ b/src/amber/cli/templates/channel/src/channels/{{name}}_channel.cr.ecr @@ -1,8 +1,8 @@ class <%= class_name %>Channel < Amber::WebSockets::Channel - def handle_joined(client_socket, message) + def handle_joined(client_socket, msg) end - def handle_message(client_socket, message) + def handle_message(client_socket, msg) end def handle_leave(client_socket) diff --git a/src/amber/cli/templates/controller/spec/controllers/spec_helper.cr.ecr b/src/amber/cli/templates/controller/spec/controllers/spec_helper.cr.ecr index cba784c4c..d47c991fb 100644 --- a/src/amber/cli/templates/controller/spec/controllers/spec_helper.cr.ecr +++ b/src/amber/cli/templates/controller/spec/controllers/spec_helper.cr.ecr @@ -1 +1,2 @@ require "../spec_helper" +require "../request_helper" diff --git a/src/amber/cli/templates/error/spec/controllers/spec_helper.cr.ecr b/src/amber/cli/templates/error/spec/controllers/spec_helper.cr.ecr index a3710231b..d47c991fb 100644 --- a/src/amber/cli/templates/error/spec/controllers/spec_helper.cr.ecr +++ b/src/amber/cli/templates/error/spec/controllers/spec_helper.cr.ecr @@ -1,2 +1,2 @@ require "../spec_helper" -require "garnet_spec" +require "../request_helper" diff --git a/src/amber/cli/templates/error/spec/controllers/{{name}}_controller_spec.cr.ecr b/src/amber/cli/templates/error/spec/controllers/{{name}}_controller_spec.cr.ecr index 72fa74e33..da8f27e37 100644 --- a/src/amber/cli/templates/error/spec/controllers/{{name}}_controller_spec.cr.ecr +++ b/src/amber/cli/templates/error/spec/controllers/{{name}}_controller_spec.cr.ecr @@ -28,7 +28,8 @@ describe <%= class_name %>Controller do end # Controller Integration Test -class <%= class_name %>ControllerTest < GarnetSpec::SystemTest +class <%= class_name %>ControllerTest + include RequestHelper getter handler : Amber::Pipe::Pipeline def initialize diff --git a/src/amber/cli/templates/scaffold/controller/spec/controllers/spec_helper.cr.ecr b/src/amber/cli/templates/scaffold/controller/spec/controllers/spec_helper.cr.ecr index cba784c4c..d47c991fb 100644 --- a/src/amber/cli/templates/scaffold/controller/spec/controllers/spec_helper.cr.ecr +++ b/src/amber/cli/templates/scaffold/controller/spec/controllers/spec_helper.cr.ecr @@ -1 +1,2 @@ require "../spec_helper" +require "../request_helper" diff --git a/src/amber/cli/templates/scaffold/controller/spec/controllers/{{name}}_controller_spec.cr.ecr b/src/amber/cli/templates/scaffold/controller/spec/controllers/{{name}}_controller_spec.cr.ecr index 33fb6acd3..79812e908 100644 --- a/src/amber/cli/templates/scaffold/controller/spec/controllers/{{name}}_controller_spec.cr.ecr +++ b/src/amber/cli/templates/scaffold/controller/spec/controllers/{{name}}_controller_spec.cr.ecr @@ -25,7 +25,8 @@ def <%= create_model_method %> model end -class <%= class_name %>ControllerTest < GarnetSpec::SystemTest +class <%= class_name %>ControllerTest + include RequestHelper getter handler : Amber::Pipe::Pipeline def initialize