From ef00d0dd7dcf2d466dfad4f97ea18b97be1abd3d Mon Sep 17 00:00:00 2001 From: Morgan Aubert Date: Wed, 21 Aug 2024 21:06:03 -0400 Subject: [PATCH] Add missing specs for the routes management command --- spec/marten/cli/manage/command/routes_spec.cr | 56 +++++++++++++++++++ spec/test_project.cr | 10 ++++ 2 files changed, 66 insertions(+) create mode 100644 spec/marten/cli/manage/command/routes_spec.cr diff --git a/spec/marten/cli/manage/command/routes_spec.cr b/spec/marten/cli/manage/command/routes_spec.cr new file mode 100644 index 00000000..252c8e84 --- /dev/null +++ b/spec/marten/cli/manage/command/routes_spec.cr @@ -0,0 +1,56 @@ +require "./spec_helper" + +describe Marten::CLI::Manage::Command::Routes do + describe "#run" do + it "displays top-level routes as expected" do + stdout = IO::Memory.new + stderr = IO::Memory.new + + command = Marten::CLI::Manage::Command::Routes.new( + options: [] of String, + stdout: stdout, + stderr: stderr + ) + + command.run + + output = stdout.rewind.gets_to_end + output.includes?("/dummy//and/").should be_true + output.includes?("[dummy_with_id_and_scope]").should be_true + end + + it "displays nested routes involving a single namespace as expected" do + stdout = IO::Memory.new + stderr = IO::Memory.new + + command = Marten::CLI::Manage::Command::Routes.new( + options: [] of String, + stdout: stdout, + stderr: stderr + ) + + command.run + + output = stdout.rewind.gets_to_end + output.includes?("/nested-1/dummy/").should be_true + output.includes?("[nested_1:dummy_with_id]").should be_true + end + + it "displays nested routes involving multiple namespaces as expected" do + stdout = IO::Memory.new + stderr = IO::Memory.new + + command = Marten::CLI::Manage::Command::Routes.new( + options: [] of String, + stdout: stdout, + stderr: stderr + ) + + command.run + + output = stdout.rewind.gets_to_end + output.includes?("/nested-1/nested-2/dummy/").should be_true + output.includes?("[nested_1:nested_2:dummy_with_id]").should be_true + end + end +end diff --git a/spec/test_project.cr b/spec/test_project.cr index 1bb621f9..a107295b 100644 --- a/spec/test_project.cr +++ b/spec/test_project.cr @@ -97,6 +97,15 @@ Marten.configure :test do |config| config.media_files.root = "spec/media" end +NESTED_ROUTES_2 = Marten::Routing::Map.draw do + path "/dummy/", DummyHandler, name: "dummy_with_id" +end + +NESTED_ROUTES_1 = Marten::Routing::Map.draw do + path "/dummy/", DummyHandler, name: "dummy_with_id" + path "/nested-2", NESTED_ROUTES_2, name: "nested_2" +end + Marten.routes.draw do path "/dummy", DummyHandler, name: "dummy" path "/dummy/", DummyHandler, name: "dummy_with_id" @@ -111,4 +120,5 @@ Marten.routes.draw do path "/cookie-value-set", CookieValueSetHandler, name: "cookie_value_set" path "/simple-schema", SimpleSchemaHandler, name: "simple_schema" path "/simple-file-schema", SimpleFileSchemaHandler, name: "simple_file_schema" + path "/nested-1", NESTED_ROUTES_1, name: "nested_1" end