Commit 7f8bf46a by Shu Fujita Committed by Andrew W. Lee

Fix messages from AnnotateRoutes (#737)

I fixed message to make them more natural English.
parent f3db77f6
...@@ -35,12 +35,12 @@ module AnnotateRoutes ...@@ -35,12 +35,12 @@ module AnnotateRoutes
new_text = new_content.join("\n") new_text = new_content.join("\n")
if rewrite_contents(existing_text, new_text) if rewrite_contents(existing_text, new_text)
puts "#{routes_file} annotated." puts "#{routes_file} was annotated."
else else
puts "#{routes_file} unchanged." puts "#{routes_file} was not changed."
end end
else else
puts "Can't find routes.rb" puts "#{routes_file} could not be found."
end end
end end
...@@ -51,12 +51,12 @@ module AnnotateRoutes ...@@ -51,12 +51,12 @@ module AnnotateRoutes
new_content = strip_on_removal(content, header_position) new_content = strip_on_removal(content, header_position)
new_text = new_content.join("\n") new_text = new_content.join("\n")
if rewrite_contents(existing_text, new_text) if rewrite_contents(existing_text, new_text)
puts "Removed annotations from #{routes_file}." puts "Annotations were removed from #{routes_file}."
else else
puts "#{routes_file} unchanged." puts "#{routes_file} was not changed (Annotation did not exist)."
end end
else else
puts "Can't find routes.rb" puts "#{routes_file} could not be found."
end end
end end
......
...@@ -3,9 +3,11 @@ require 'annotate/annotate_routes' ...@@ -3,9 +3,11 @@ require 'annotate/annotate_routes'
describe AnnotateRoutes do describe AnnotateRoutes do
ROUTE_FILE = 'config/routes.rb'.freeze ROUTE_FILE = 'config/routes.rb'.freeze
ANNOTATION_ADDED = "#{ROUTE_FILE} annotated.".freeze
ANNOTATION_REMOVED = "Removed annotations from #{ROUTE_FILE}.".freeze MESSAGE_ANNOTATED = "#{ROUTE_FILE} was annotated.".freeze
FILE_UNCHANGED = "#{ROUTE_FILE} unchanged.".freeze MESSAGE_UNCHANGED = "#{ROUTE_FILE} was not changed.".freeze
MESSAGE_NOT_FOUND = "#{ROUTE_FILE} could not be found.".freeze
MESSAGE_REMOVED = "Annotations were removed from #{ROUTE_FILE}.".freeze
MAGIC_COMMENTS = [ MAGIC_COMMENTS = [
'# encoding: UTF-8', '# encoding: UTF-8',
...@@ -31,7 +33,7 @@ describe AnnotateRoutes do ...@@ -31,7 +33,7 @@ describe AnnotateRoutes do
it 'should check if routes.rb exists' do it 'should check if routes.rb exists' do
expect(File).to receive(:exist?).with(ROUTE_FILE).and_return(false) expect(File).to receive(:exist?).with(ROUTE_FILE).and_return(false)
expect(AnnotateRoutes).to receive(:puts).with("Can't find routes.rb") expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_NOT_FOUND)
AnnotateRoutes.do_annotations AnnotateRoutes.do_annotations
end end
...@@ -50,7 +52,7 @@ describe AnnotateRoutes do ...@@ -50,7 +52,7 @@ describe AnnotateRoutes do
expect(File).to receive(:read).with(ROUTE_FILE).and_return("").at_least(:once) expect(File).to receive(:read).with(ROUTE_FILE).and_return("").at_least(:once)
expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_ADDED).at_least(:once) expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).at_least(:once)
end end
context 'without magic comments' do context 'without magic comments' do
...@@ -202,7 +204,7 @@ describe AnnotateRoutes do ...@@ -202,7 +204,7 @@ describe AnnotateRoutes do
expect(File).to receive(:read).with(ROUTE_FILE).and_return("") expect(File).to receive(:read).with(ROUTE_FILE).and_return("")
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file) expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
expect(mock_file).to receive(:puts).with("\n# == Route Map\n#\n") expect(mock_file).to receive(:puts).with("\n# == Route Map\n#\n")
expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_ADDED) expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED)
AnnotateRoutes.do_annotations AnnotateRoutes.do_annotations
end end
...@@ -211,7 +213,7 @@ describe AnnotateRoutes do ...@@ -211,7 +213,7 @@ describe AnnotateRoutes do
expect(File).to receive(:read).with(ROUTE_FILE).and_return("") expect(File).to receive(:read).with(ROUTE_FILE).and_return("")
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file) expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
expect(mock_file).to receive(:puts).with("\n# == Route Map\n#\n") expect(mock_file).to receive(:puts).with("\n# == Route Map\n#\n")
expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_ADDED) expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED)
AnnotateRoutes.do_annotations(ignore_routes: 'my_route') AnnotateRoutes.do_annotations(ignore_routes: 'my_route')
end end
...@@ -220,14 +222,14 @@ describe AnnotateRoutes do ...@@ -220,14 +222,14 @@ describe AnnotateRoutes do
expect(File).to receive(:read).with(ROUTE_FILE).and_return("") expect(File).to receive(:read).with(ROUTE_FILE).and_return("")
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file) expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
expect(mock_file).to receive(:puts).with("# == Route Map\n#\n") expect(mock_file).to receive(:puts).with("# == Route Map\n#\n")
expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_ADDED) expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED)
AnnotateRoutes.do_annotations(position_in_routes: 'top') AnnotateRoutes.do_annotations(position_in_routes: 'top')
end end
it 'should skip annotations if file does already contain annotation' do it 'should skip annotations if file does already contain annotation' do
expect(File).to receive(:read).with(ROUTE_FILE).and_return("\n# == Route Map\n#\n") expect(File).to receive(:read).with(ROUTE_FILE).and_return("\n# == Route Map\n#\n")
expect(AnnotateRoutes).to receive(:puts).with(FILE_UNCHANGED) expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_UNCHANGED)
AnnotateRoutes.do_annotations AnnotateRoutes.do_annotations
end end
...@@ -240,7 +242,7 @@ describe AnnotateRoutes do ...@@ -240,7 +242,7 @@ describe AnnotateRoutes do
MAGIC_COMMENTS.each do |magic_comment| MAGIC_COMMENTS.each do |magic_comment|
expect(File).to receive(:read).with(ROUTE_FILE).and_return("#{magic_comment}\nSomething") expect(File).to receive(:read).with(ROUTE_FILE).and_return("#{magic_comment}\nSomething")
expect(mock_file).to receive(:puts).with("#{magic_comment}\n\n# == Route Map\n#\n\nSomething\n") expect(mock_file).to receive(:puts).with("#{magic_comment}\n\n# == Route Map\n#\n\nSomething\n")
expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_ADDED) expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED)
AnnotateRoutes.do_annotations(position_in_routes: 'top') AnnotateRoutes.do_annotations(position_in_routes: 'top')
end end
end end
...@@ -252,7 +254,7 @@ describe AnnotateRoutes do ...@@ -252,7 +254,7 @@ describe AnnotateRoutes do
MAGIC_COMMENTS.each do |magic_comment| MAGIC_COMMENTS.each do |magic_comment|
expect(File).to receive(:read).with(ROUTE_FILE).and_return("#{magic_comment}\nSomething") expect(File).to receive(:read).with(ROUTE_FILE).and_return("#{magic_comment}\nSomething")
expect(mock_file).to receive(:puts).with("#{magic_comment}\nSomething\n\n# == Route Map\n#\n") expect(mock_file).to receive(:puts).with("#{magic_comment}\nSomething\n\n# == Route Map\n#\n")
expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_ADDED) expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED)
AnnotateRoutes.do_annotations(position_in_routes: 'bottom') AnnotateRoutes.do_annotations(position_in_routes: 'bottom')
end end
end end
...@@ -261,7 +263,7 @@ describe AnnotateRoutes do ...@@ -261,7 +263,7 @@ describe AnnotateRoutes do
MAGIC_COMMENTS.each do |magic_comment| MAGIC_COMMENTS.each do |magic_comment|
expect(File).to receive(:read).with(ROUTE_FILE) expect(File).to receive(:read).with(ROUTE_FILE)
.and_return("#{magic_comment}\n\n# == Route Map\n#\n") .and_return("#{magic_comment}\n\n# == Route Map\n#\n")
expect(AnnotateRoutes).to receive(:puts).with(FILE_UNCHANGED) expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_UNCHANGED)
AnnotateRoutes.do_annotations AnnotateRoutes.do_annotations
end end
...@@ -274,7 +276,7 @@ describe AnnotateRoutes do ...@@ -274,7 +276,7 @@ describe AnnotateRoutes do
expect(File).to receive(:exist?).with(ROUTE_FILE).and_return(true) expect(File).to receive(:exist?).with(ROUTE_FILE).and_return(true)
expect(AnnotateRoutes).to receive(:`).with('rake routes').and_return("(in /bad/line)\ngood line") expect(AnnotateRoutes).to receive(:`).with('rake routes').and_return("(in /bad/line)\ngood line")
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file) expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_ADDED) expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED)
end end
it 'should annotate and add a newline!' do it 'should annotate and add a newline!' do
...@@ -295,7 +297,7 @@ describe AnnotateRoutes do ...@@ -295,7 +297,7 @@ describe AnnotateRoutes do
expect(File).to receive(:exist?).with(ROUTE_FILE).and_return(true) expect(File).to receive(:exist?).with(ROUTE_FILE).and_return(true)
expect(AnnotateRoutes).to receive(:`).with('rake routes').and_return("another good line\ngood line") expect(AnnotateRoutes).to receive(:`).with('rake routes').and_return("another good line\ngood line")
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file) expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_ADDED) expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED)
end end
it 'should annotate and add a newline!' do it 'should annotate and add a newline!' do
...@@ -321,7 +323,7 @@ describe AnnotateRoutes do ...@@ -321,7 +323,7 @@ describe AnnotateRoutes do
before(:each) do before(:each) do
expect(File).to receive(:exist?).with(ROUTE_FILE).and_return(true) expect(File).to receive(:exist?).with(ROUTE_FILE).and_return(true)
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file) expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file)
expect(AnnotateRoutes).to receive(:puts).with(ANNOTATION_REMOVED) expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_REMOVED)
end end
it 'should remove trailing annotation and trim trailing newlines, but leave leading newlines alone' do it 'should remove trailing annotation and trim trailing newlines, but leave leading newlines alone' do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment