Skip to content

Commit 0c601a1

Browse files
committed
Rename constants
1 parent e494347 commit 0c601a1

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

spec/lib/annotate/annotate_routes_spec.rb

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33

44
describe AnnotateRoutes do
55
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
1011

1112
def mock_file(stubs = {})
1213
@mock_file ||= double(File, stubs)
@@ -30,7 +31,7 @@ def magic_comments_list_each
3031

3132
it 'should check if routes.rb exists' do
3233
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)
3435
AnnotateRoutes.do_annotations
3536
end
3637

@@ -47,7 +48,7 @@ def magic_comments_list_each
4748

4849
expect(File).to receive(:read).with(ROUTE_FILE).and_return("").at_least(:once)
4950

50-
expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_ADDED).at_least(:once)
51+
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).at_least(:once)
5152
end
5253

5354
context 'without magic comments' do
@@ -175,7 +176,7 @@ def magic_comments_list_each
175176
expect(File).to receive(:read).with(ROUTE_FILE).and_return("")
176177
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
177178
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)
179180

180181
AnnotateRoutes.do_annotations
181182
end
@@ -184,7 +185,7 @@ def magic_comments_list_each
184185
expect(File).to receive(:read).with(ROUTE_FILE).and_return("")
185186
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
186187
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)
188189

189190
AnnotateRoutes.do_annotations(ignore_routes: 'my_route')
190191
end
@@ -193,14 +194,14 @@ def magic_comments_list_each
193194
expect(File).to receive(:read).with(ROUTE_FILE).and_return("")
194195
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
195196
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)
197198

198199
AnnotateRoutes.do_annotations(position_in_routes: 'top')
199200
end
200201

201202
it 'should skip annotations if file does already contain annotation' do
202203
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)
204205

205206
AnnotateRoutes.do_annotations
206207
end
@@ -213,7 +214,7 @@ def magic_comments_list_each
213214
magic_comments_list_each do |magic_comment|
214215
expect(File).to receive(:read).with(ROUTE_FILE).and_return("#{magic_comment}\nSomething")
215216
expect(@mock_file).to receive(:puts).with("#{magic_comment}\n\n# == Route Map\n#\n\nSomething\n")
216-
expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_ADDED)
217+
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED)
217218
AnnotateRoutes.do_annotations(position_in_routes: 'top')
218219
end
219220
end
@@ -225,7 +226,7 @@ def magic_comments_list_each
225226
magic_comments_list_each do |magic_comment|
226227
expect(File).to receive(:read).with(ROUTE_FILE).and_return("#{magic_comment}\nSomething")
227228
expect(@mock_file).to receive(:puts).with("#{magic_comment}\nSomething\n\n# == Route Map\n#\n")
228-
expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_ADDED)
229+
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED)
229230
AnnotateRoutes.do_annotations(position_in_routes: 'bottom')
230231
end
231232
end
@@ -234,7 +235,7 @@ def magic_comments_list_each
234235
magic_comments_list_each do |magic_comment|
235236
expect(File).to receive(:read).with(ROUTE_FILE)
236237
.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)
238239

239240
AnnotateRoutes.do_annotations
240241
end
@@ -247,7 +248,7 @@ def magic_comments_list_each
247248
expect(File).to receive(:exist?).with(ROUTE_FILE).and_return(true)
248249
expect(AnnotateRoutes).to receive(:`).with('rake routes').and_return("(in /bad/line)\ngood line")
249250
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)
251252
end
252253

253254
it 'should annotate and add a newline!' do
@@ -268,7 +269,7 @@ def magic_comments_list_each
268269
expect(File).to receive(:exist?).with(ROUTE_FILE).and_return(true)
269270
expect(AnnotateRoutes).to receive(:`).with('rake routes').and_return("another good line\ngood line")
270271
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)
272273
end
273274

274275
it 'should annotate and add a newline!' do
@@ -294,7 +295,7 @@ def magic_comments_list_each
294295
before(:each) do
295296
expect(File).to receive(:exist?).with(ROUTE_FILE).and_return(true)
296297
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)
298299
end
299300

300301
it 'should remove trailing annotation and trim trailing newlines, but leave leading newlines alone' do

0 commit comments

Comments
 (0)