@@ -18,23 +18,21 @@ def output
18
18
19
19
context "generating for app" do
20
20
it "generates an operation" do
21
- subject . call ( name : "operations/ add_book" )
21
+ subject . call ( name : "add_book" )
22
22
23
23
operation_file = <<~EXPECTED
24
24
# frozen_string_literal: true
25
25
26
26
module Test
27
- module Operations
28
- class AddBook < Test::Operation
29
- def call
30
- end
27
+ class AddBook < Test::Operation
28
+ def call
31
29
end
32
30
end
33
31
end
34
32
EXPECTED
35
33
36
- expect ( fs . read ( "app/operations/ add_book.rb" ) ) . to eq ( operation_file )
37
- expect ( output ) . to include ( "Created app/operations/ add_book.rb" )
34
+ expect ( fs . read ( "app/add_book.rb" ) ) . to eq ( operation_file )
35
+ expect ( output ) . to include ( "Created app/add_book.rb" )
38
36
end
39
37
40
38
it "generates a operation in a deep namespace with default separator" do
@@ -59,7 +57,7 @@ def call
59
57
expect ( output ) . to include ( "Created app/admin/books/add.rb" )
60
58
end
61
59
62
- it "generates an operation in a deep namespace with slash separator " do
60
+ it "generates an operation in a deep namespace with slash separators " do
63
61
subject . call ( name : "admin/books/add" )
64
62
65
63
operation_file = <<~EXPECTED
@@ -80,78 +78,26 @@ def call
80
78
expect ( fs . read ( "app/admin/books/add.rb" ) ) . to eq ( operation_file )
81
79
expect ( output ) . to include ( "Created app/admin/books/add.rb" )
82
80
end
83
-
84
- it "outputs an error if trying to generate an operation without a separator" do
85
- expect {
86
- subject . call ( name : "add_book" )
87
- } . to raise_error ( Hanami ::CLI ::NameNeedsNamespaceError ) . with_message (
88
- "Failed to create operation `add_book'. " \
89
- "This would create the operation directly in the `app/' folder. " \
90
- "Instead, you should provide a namespace for the folder where this operation will live. " \
91
- "NOTE: We recommend giving it a name that's specific to your domain, " \
92
- "but you can also use `operations.add_book' in the meantime if you're unsure."
93
- )
94
- expect ( fs . exist? ( "app/add_book.rb" ) ) . to be ( false )
95
- end
96
81
end
97
82
98
83
context "generating for a slice" do
99
- it "generates a operation" do
100
- fs . mkdir ( "slices/main" )
101
- subject . call ( name : "operations.add_book" , slice : "main" )
102
-
103
- operation_file = <<~EXPECTED
104
- # frozen_string_literal: true
105
-
106
- module Main
107
- module Operations
108
- class AddBook < Main::Operation
109
- def call
110
- end
111
- end
112
- end
113
- end
114
- EXPECTED
115
-
116
- expect ( fs . read ( "slices/main/operations/add_book.rb" ) ) . to eq ( operation_file )
117
- expect ( output ) . to include ( "Created slices/main/operations/add_book.rb" )
118
- end
119
-
120
- it "generates a operation in a deep namespace with default separator" do
84
+ it "generates a operation in a top-level namespace" do
121
85
fs . mkdir ( "slices/main" )
122
- subject . call ( name : "admin.books.add " , slice : "main" )
86
+ subject . call ( name : "add_book " , slice : "main" )
123
87
124
88
operation_file = <<~EXPECTED
125
89
# frozen_string_literal: true
126
90
127
91
module Main
128
- module Admin
129
- module Books
130
- class Add < Main::Operation
131
- def call
132
- end
133
- end
92
+ class AddBook < Main::Operation
93
+ def call
134
94
end
135
95
end
136
96
end
137
97
EXPECTED
138
98
139
- expect ( fs . read ( "slices/main/admin/books/add.rb" ) ) . to eq ( operation_file )
140
- expect ( output ) . to include ( "Created slices/main/admin/books/add.rb" )
141
- end
142
-
143
- it "outputs an error if trying to generate an operation without a separator" do
144
- fs . mkdir ( "slices/main" )
145
- expect {
146
- subject . call ( name : "add_book" , slice : "main" )
147
- } . to raise_error ( Hanami ::CLI ::NameNeedsNamespaceError ) . with_message (
148
- "Failed to create operation `add_book'. " \
149
- "This would create the operation directly in the `slices/main/' folder. " \
150
- "Instead, you should provide a namespace for the folder where this operation will live. " \
151
- "NOTE: We recommend giving it a name that's specific to your domain, " \
152
- "but you can also use `operations.add_book' in the meantime if you're unsure."
153
- )
154
- expect ( fs . exist? ( "app/add_book.rb" ) ) . to be ( false )
99
+ expect ( fs . read ( "slices/main/add_book.rb" ) ) . to eq ( operation_file )
100
+ expect ( output ) . to include ( "Created slices/main/add_book.rb" )
155
101
end
156
102
end
157
103
end
0 commit comments