Skip to content

Commit 7f8bf46

Browse files
nard-techdrwl
authored andcommitted
Fix messages from AnnotateRoutes (#737)
I fixed message to make them more natural English.
1 parent f3db77f commit 7f8bf46

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

lib/annotate/annotate_routes.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ def do_annotations(options = {})
3535
new_text = new_content.join("\n")
3636

3737
if rewrite_contents(existing_text, new_text)
38-
puts "#{routes_file} annotated."
38+
puts "#{routes_file} was annotated."
3939
else
40-
puts "#{routes_file} unchanged."
40+
puts "#{routes_file} was not changed."
4141
end
4242
else
43-
puts "Can't find routes.rb"
43+
puts "#{routes_file} could not be found."
4444
end
4545
end
4646

@@ -51,12 +51,12 @@ def remove_annotations(_options={})
5151
new_content = strip_on_removal(content, header_position)
5252
new_text = new_content.join("\n")
5353
if rewrite_contents(existing_text, new_text)
54-
puts "Removed annotations from #{routes_file}."
54+
puts "Annotations were removed from #{routes_file}."
5555
else
56-
puts "#{routes_file} unchanged."
56+
puts "#{routes_file} was not changed (Annotation did not exist)."
5757
end
5858
else
59-
puts "Can't find routes.rb"
59+
puts "#{routes_file} could not be found."
6060
end
6161
end
6262

spec/lib/annotate/annotate_routes_spec.rb

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

44
describe AnnotateRoutes do
55
ROUTE_FILE = 'config/routes.rb'.freeze
6-
ANNOTATION_ADDED = "#{ROUTE_FILE} annotated.".freeze
7-
ANNOTATION_REMOVED = "Removed annotations from #{ROUTE_FILE}.".freeze
8-
FILE_UNCHANGED = "#{ROUTE_FILE} unchanged.".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
911

1012
MAGIC_COMMENTS = [
1113
'# encoding: UTF-8',
@@ -31,7 +33,7 @@
3133

3234
it 'should check if routes.rb exists' do
3335
expect(File).to receive(:exist?).with(ROUTE_FILE).and_return(false)
34-
expect(AnnotateRoutes).to receive(:puts).with("Can't find routes.rb")
36+
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_NOT_FOUND)
3537
AnnotateRoutes.do_annotations
3638
end
3739

@@ -50,7 +52,7 @@
5052

5153
expect(File).to receive(:read).with(ROUTE_FILE).and_return("").at_least(:once)
5254

53-
expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_ADDED).at_least(:once)
55+
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).at_least(:once)
5456
end
5557

5658
context 'without magic comments' do
@@ -202,7 +204,7 @@
202204
expect(File).to receive(:read).with(ROUTE_FILE).and_return("")
203205
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
204206
expect(mock_file).to receive(:puts).with("\n# == Route Map\n#\n")
205-
expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_ADDED)
207+
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED)
206208

207209
AnnotateRoutes.do_annotations
208210
end
@@ -211,7 +213,7 @@
211213
expect(File).to receive(:read).with(ROUTE_FILE).and_return("")
212214
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
213215
expect(mock_file).to receive(:puts).with("\n# == Route Map\n#\n")
214-
expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_ADDED)
216+
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED)
215217

216218
AnnotateRoutes.do_annotations(ignore_routes: 'my_route')
217219
end
@@ -220,14 +222,14 @@
220222
expect(File).to receive(:read).with(ROUTE_FILE).and_return("")
221223
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
222224
expect(mock_file).to receive(:puts).with("# == Route Map\n#\n")
223-
expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_ADDED)
225+
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED)
224226

225227
AnnotateRoutes.do_annotations(position_in_routes: 'top')
226228
end
227229

228230
it 'should skip annotations if file does already contain annotation' do
229231
expect(File).to receive(:read).with(ROUTE_FILE).and_return("\n# == Route Map\n#\n")
230-
expect(AnnotateRoutes).to receive(:puts).with(FILE_UNCHANGED)
232+
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_UNCHANGED)
231233

232234
AnnotateRoutes.do_annotations
233235
end
@@ -240,7 +242,7 @@
240242
MAGIC_COMMENTS.each do |magic_comment|
241243
expect(File).to receive(:read).with(ROUTE_FILE).and_return("#{magic_comment}\nSomething")
242244
expect(mock_file).to receive(:puts).with("#{magic_comment}\n\n# == Route Map\n#\n\nSomething\n")
243-
expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_ADDED)
245+
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED)
244246
AnnotateRoutes.do_annotations(position_in_routes: 'top')
245247
end
246248
end
@@ -252,7 +254,7 @@
252254
MAGIC_COMMENTS.each do |magic_comment|
253255
expect(File).to receive(:read).with(ROUTE_FILE).and_return("#{magic_comment}\nSomething")
254256
expect(mock_file).to receive(:puts).with("#{magic_comment}\nSomething\n\n# == Route Map\n#\n")
255-
expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_ADDED)
257+
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED)
256258
AnnotateRoutes.do_annotations(position_in_routes: 'bottom')
257259
end
258260
end
@@ -261,7 +263,7 @@
261263
MAGIC_COMMENTS.each do |magic_comment|
262264
expect(File).to receive(:read).with(ROUTE_FILE)
263265
.and_return("#{magic_comment}\n\n# == Route Map\n#\n")
264-
expect(AnnotateRoutes).to receive(:puts).with(FILE_UNCHANGED)
266+
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_UNCHANGED)
265267

266268
AnnotateRoutes.do_annotations
267269
end
@@ -274,7 +276,7 @@
274276
expect(File).to receive(:exist?).with(ROUTE_FILE).and_return(true)
275277
expect(AnnotateRoutes).to receive(:`).with('rake routes').and_return("(in /bad/line)\ngood line")
276278
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
277-
expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_ADDED)
279+
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED)
278280
end
279281

280282
it 'should annotate and add a newline!' do
@@ -295,7 +297,7 @@
295297
expect(File).to receive(:exist?).with(ROUTE_FILE).and_return(true)
296298
expect(AnnotateRoutes).to receive(:`).with('rake routes').and_return("another good line\ngood line")
297299
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
298-
expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_ADDED)
300+
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED)
299301
end
300302

301303
it 'should annotate and add a newline!' do
@@ -321,7 +323,7 @@
321323
before(:each) do
322324
expect(File).to receive(:exist?).with(ROUTE_FILE).and_return(true)
323325
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
324-
expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_REMOVED)
326+
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_REMOVED)
325327
end
326328

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

0 commit comments

Comments
 (0)