Skip to content

Commit ef00d0d

Browse files
committed
Add missing specs for the routes management command
1 parent 91328a9 commit ef00d0d

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
require "./spec_helper"
2+
3+
describe Marten::CLI::Manage::Command::Routes do
4+
describe "#run" do
5+
it "displays top-level routes as expected" do
6+
stdout = IO::Memory.new
7+
stderr = IO::Memory.new
8+
9+
command = Marten::CLI::Manage::Command::Routes.new(
10+
options: [] of String,
11+
stdout: stdout,
12+
stderr: stderr
13+
)
14+
15+
command.run
16+
17+
output = stdout.rewind.gets_to_end
18+
output.includes?("/dummy/<id:int>/and/<scope:slug>").should be_true
19+
output.includes?("[dummy_with_id_and_scope]").should be_true
20+
end
21+
22+
it "displays nested routes involving a single namespace as expected" do
23+
stdout = IO::Memory.new
24+
stderr = IO::Memory.new
25+
26+
command = Marten::CLI::Manage::Command::Routes.new(
27+
options: [] of String,
28+
stdout: stdout,
29+
stderr: stderr
30+
)
31+
32+
command.run
33+
34+
output = stdout.rewind.gets_to_end
35+
output.includes?("/nested-1/dummy/<id:int>").should be_true
36+
output.includes?("[nested_1:dummy_with_id]").should be_true
37+
end
38+
39+
it "displays nested routes involving multiple namespaces as expected" do
40+
stdout = IO::Memory.new
41+
stderr = IO::Memory.new
42+
43+
command = Marten::CLI::Manage::Command::Routes.new(
44+
options: [] of String,
45+
stdout: stdout,
46+
stderr: stderr
47+
)
48+
49+
command.run
50+
51+
output = stdout.rewind.gets_to_end
52+
output.includes?("/nested-1/nested-2/dummy/<id:int>").should be_true
53+
output.includes?("[nested_1:nested_2:dummy_with_id]").should be_true
54+
end
55+
end
56+
end

spec/test_project.cr

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ Marten.configure :test do |config|
9797
config.media_files.root = "spec/media"
9898
end
9999

100+
NESTED_ROUTES_2 = Marten::Routing::Map.draw do
101+
path "/dummy/<id:int>", DummyHandler, name: "dummy_with_id"
102+
end
103+
104+
NESTED_ROUTES_1 = Marten::Routing::Map.draw do
105+
path "/dummy/<id:int>", DummyHandler, name: "dummy_with_id"
106+
path "/nested-2", NESTED_ROUTES_2, name: "nested_2"
107+
end
108+
100109
Marten.routes.draw do
101110
path "/dummy", DummyHandler, name: "dummy"
102111
path "/dummy/<id:int>", DummyHandler, name: "dummy_with_id"
@@ -111,4 +120,5 @@ Marten.routes.draw do
111120
path "/cookie-value-set", CookieValueSetHandler, name: "cookie_value_set"
112121
path "/simple-schema", SimpleSchemaHandler, name: "simple_schema"
113122
path "/simple-file-schema", SimpleFileSchemaHandler, name: "simple_file_schema"
123+
path "/nested-1", NESTED_ROUTES_1, name: "nested_1"
114124
end

0 commit comments

Comments
 (0)