3
3
4
4
describe AnnotateRoutes do
5
5
ROUTE_FILE = 'config/routes.rb' . freeze
6
- ANNOTATION_ADDED = "#{ ROUTE_FILE } was annotated." . freeze
7
- ANNOTATION_FILE_UNCHANGED = "#{ ROUTE_FILE } was not changed." . freeze
8
- ANNOTATION_FILE_COULD_NOT_FOUND = "#{ ROUTE_FILE } could not be found." . freeze
9
- ANNOTATION_REMOVED = "Annotations were removed from #{ ROUTE_FILE } ." . freeze
6
+
7
+ MESSAGE_ANNOTATED = "#{ ROUTE_FILE } was annotated." . freeze
8
+ MESSAGE_UNCHANGED = "#{ ROUTE_FILE } was not changed." . freeze
9
+ MESSAGE_NOT_FOUND = "#{ ROUTE_FILE } could not be found." . freeze
10
+ MESSAGE_REMOVED = "Annotations were removed from #{ ROUTE_FILE } ." . freeze
10
11
11
12
def mock_file ( stubs = { } )
12
13
@mock_file ||= double ( File , stubs )
@@ -30,7 +31,7 @@ def magic_comments_list_each
30
31
31
32
it 'should check if routes.rb exists' do
32
33
expect ( File ) . to receive ( :exist? ) . with ( ROUTE_FILE ) . and_return ( false )
33
- expect ( AnnotateRoutes ) . to receive ( :puts ) . with ( ANNOTATION_FILE_COULD_NOT_FOUND )
34
+ expect ( AnnotateRoutes ) . to receive ( :puts ) . with ( MESSAGE_NOT_FOUND )
34
35
AnnotateRoutes . do_annotations
35
36
end
36
37
@@ -47,7 +48,7 @@ def magic_comments_list_each
47
48
48
49
expect ( File ) . to receive ( :read ) . with ( ROUTE_FILE ) . and_return ( "" ) . at_least ( :once )
49
50
50
- expect ( AnnotateRoutes ) . to receive ( :puts ) . with ( ANNOTATION_ADDED ) . at_least ( :once )
51
+ expect ( AnnotateRoutes ) . to receive ( :puts ) . with ( MESSAGE_ANNOTATED ) . at_least ( :once )
51
52
end
52
53
53
54
context 'without magic comments' do
@@ -73,7 +74,7 @@ def magic_comments_list_each
73
74
expect ( @mock_file ) . to receive ( :puts ) . with ( "
74
75
# ## Route Map
75
76
#
76
- # Prefix | Verb | URI Pattern | Controller#Action
77
+ # Prefix | Verb | URI Pattern | Controller#Action
77
78
# --------- | ---------- | --------------- | --------------------
78
79
# myaction1 | GET | /url1(.:format) | mycontroller1#action
79
80
# myaction2 | POST | /url2(.:format) | mycontroller2#action
@@ -130,7 +131,7 @@ def magic_comments_list_each
130
131
131
132
# ## Route Map
132
133
#
133
- # Prefix | Verb | URI Pattern | Controller#Action
134
+ # Prefix | Verb | URI Pattern | Controller#Action
134
135
# --------- | ---------- | --------------- | --------------------
135
136
# myaction1 | GET | /url1(.:format) | mycontroller1#action
136
137
# myaction2 | POST | /url2(.:format) | mycontroller2#action
@@ -175,7 +176,7 @@ def magic_comments_list_each
175
176
expect ( File ) . to receive ( :read ) . with ( ROUTE_FILE ) . and_return ( "" )
176
177
expect ( File ) . to receive ( :open ) . with ( ROUTE_FILE , 'wb' ) . and_yield ( mock_file )
177
178
expect ( @mock_file ) . to receive ( :puts ) . with ( "\n # == Route Map\n #\n " )
178
- expect ( AnnotateRoutes ) . to receive ( :puts ) . with ( ANNOTATION_ADDED )
179
+ expect ( AnnotateRoutes ) . to receive ( :puts ) . with ( MESSAGE_ANNOTATED )
179
180
180
181
AnnotateRoutes . do_annotations
181
182
end
@@ -184,7 +185,7 @@ def magic_comments_list_each
184
185
expect ( File ) . to receive ( :read ) . with ( ROUTE_FILE ) . and_return ( "" )
185
186
expect ( File ) . to receive ( :open ) . with ( ROUTE_FILE , 'wb' ) . and_yield ( mock_file )
186
187
expect ( @mock_file ) . to receive ( :puts ) . with ( "\n # == Route Map\n #\n " )
187
- expect ( AnnotateRoutes ) . to receive ( :puts ) . with ( ANNOTATION_ADDED )
188
+ expect ( AnnotateRoutes ) . to receive ( :puts ) . with ( MESSAGE_ANNOTATED )
188
189
189
190
AnnotateRoutes . do_annotations ( ignore_routes : 'my_route' )
190
191
end
@@ -193,14 +194,14 @@ def magic_comments_list_each
193
194
expect ( File ) . to receive ( :read ) . with ( ROUTE_FILE ) . and_return ( "" )
194
195
expect ( File ) . to receive ( :open ) . with ( ROUTE_FILE , 'wb' ) . and_yield ( mock_file )
195
196
expect ( @mock_file ) . to receive ( :puts ) . with ( "# == Route Map\n #\n " )
196
- expect ( AnnotateRoutes ) . to receive ( :puts ) . with ( ANNOTATION_ADDED )
197
+ expect ( AnnotateRoutes ) . to receive ( :puts ) . with ( MESSAGE_ANNOTATED )
197
198
198
199
AnnotateRoutes . do_annotations ( position_in_routes : 'top' )
199
200
end
200
201
201
202
it 'should skip annotations if file does already contain annotation' do
202
203
expect ( File ) . to receive ( :read ) . with ( ROUTE_FILE ) . and_return ( "\n # == Route Map\n #\n " )
203
- expect ( AnnotateRoutes ) . to receive ( :puts ) . with ( ANNOTATION_FILE_UNCHANGED )
204
+ expect ( AnnotateRoutes ) . to receive ( :puts ) . with ( MESSAGE_UNCHANGED )
204
205
205
206
AnnotateRoutes . do_annotations
206
207
end
@@ -213,7 +214,7 @@ def magic_comments_list_each
213
214
magic_comments_list_each do |magic_comment |
214
215
expect ( File ) . to receive ( :read ) . with ( ROUTE_FILE ) . and_return ( "#{ magic_comment } \n Something" )
215
216
expect ( @mock_file ) . to receive ( :puts ) . with ( "#{ magic_comment } \n \n # == Route Map\n #\n \n Something\n " )
216
- expect ( AnnotateRoutes ) . to receive ( :puts ) . with ( ANNOTATION_ADDED )
217
+ expect ( AnnotateRoutes ) . to receive ( :puts ) . with ( MESSAGE_ANNOTATED )
217
218
AnnotateRoutes . do_annotations ( position_in_routes : 'top' )
218
219
end
219
220
end
@@ -225,7 +226,7 @@ def magic_comments_list_each
225
226
magic_comments_list_each do |magic_comment |
226
227
expect ( File ) . to receive ( :read ) . with ( ROUTE_FILE ) . and_return ( "#{ magic_comment } \n Something" )
227
228
expect ( @mock_file ) . to receive ( :puts ) . with ( "#{ magic_comment } \n Something\n \n # == Route Map\n #\n " )
228
- expect ( AnnotateRoutes ) . to receive ( :puts ) . with ( ANNOTATION_ADDED )
229
+ expect ( AnnotateRoutes ) . to receive ( :puts ) . with ( MESSAGE_ANNOTATED )
229
230
AnnotateRoutes . do_annotations ( position_in_routes : 'bottom' )
230
231
end
231
232
end
@@ -234,7 +235,7 @@ def magic_comments_list_each
234
235
magic_comments_list_each do |magic_comment |
235
236
expect ( File ) . to receive ( :read ) . with ( ROUTE_FILE )
236
237
. and_return ( "#{ magic_comment } \n \n # == Route Map\n #\n " )
237
- expect ( AnnotateRoutes ) . to receive ( :puts ) . with ( ANNOTATION_FILE_UNCHANGED )
238
+ expect ( AnnotateRoutes ) . to receive ( :puts ) . with ( MESSAGE_UNCHANGED )
238
239
239
240
AnnotateRoutes . do_annotations
240
241
end
@@ -247,7 +248,7 @@ def magic_comments_list_each
247
248
expect ( File ) . to receive ( :exist? ) . with ( ROUTE_FILE ) . and_return ( true )
248
249
expect ( AnnotateRoutes ) . to receive ( :` ) . with ( 'rake routes' ) . and_return ( "(in /bad/line)\n good line" )
249
250
expect ( File ) . to receive ( :open ) . with ( ROUTE_FILE , 'wb' ) . and_yield ( mock_file )
250
- expect ( AnnotateRoutes ) . to receive ( :puts ) . with ( ANNOTATION_ADDED )
251
+ expect ( AnnotateRoutes ) . to receive ( :puts ) . with ( MESSAGE_ANNOTATED )
251
252
end
252
253
253
254
it 'should annotate and add a newline!' do
@@ -268,7 +269,7 @@ def magic_comments_list_each
268
269
expect ( File ) . to receive ( :exist? ) . with ( ROUTE_FILE ) . and_return ( true )
269
270
expect ( AnnotateRoutes ) . to receive ( :` ) . with ( 'rake routes' ) . and_return ( "another good line\n good line" )
270
271
expect ( File ) . to receive ( :open ) . with ( ROUTE_FILE , 'wb' ) . and_yield ( mock_file )
271
- expect ( AnnotateRoutes ) . to receive ( :puts ) . with ( ANNOTATION_ADDED )
272
+ expect ( AnnotateRoutes ) . to receive ( :puts ) . with ( MESSAGE_ANNOTATED )
272
273
end
273
274
274
275
it 'should annotate and add a newline!' do
@@ -294,7 +295,7 @@ def magic_comments_list_each
294
295
before ( :each ) do
295
296
expect ( File ) . to receive ( :exist? ) . with ( ROUTE_FILE ) . and_return ( true )
296
297
expect ( File ) . to receive ( :open ) . with ( ROUTE_FILE , 'wb' ) . and_yield ( mock_file )
297
- expect ( AnnotateRoutes ) . to receive ( :puts ) . with ( ANNOTATION_REMOVED )
298
+ expect ( AnnotateRoutes ) . to receive ( :puts ) . with ( MESSAGE_REMOVED )
298
299
end
299
300
300
301
it 'should remove trailing annotation and trim trailing newlines, but leave leading newlines alone' do
0 commit comments