Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
annotate
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
annotate
Commits
7f8bf46a
Commit
7f8bf46a
authored
Jan 28, 2020
by
Shu Fujita
Committed by
Andrew W. Lee
Jan 27, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix messages from AnnotateRoutes (#737)
I fixed message to make them more natural English.
parent
f3db77f6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
21 deletions
+23
-21
annotate_routes.rb
lib/annotate/annotate_routes.rb
+6
-6
annotate_routes_spec.rb
spec/lib/annotate/annotate_routes_spec.rb
+17
-15
No files found.
lib/annotate/annotate_routes.rb
View file @
7f8bf46a
...
...
@@ -35,12 +35,12 @@ module AnnotateRoutes
new_text
=
new_content
.
join
(
"
\n
"
)
if
rewrite_contents
(
existing_text
,
new_text
)
puts
"
#{
routes_file
}
annotated."
puts
"
#{
routes_file
}
was
annotated."
else
puts
"
#{
routes_file
}
un
changed."
puts
"
#{
routes_file
}
was not
changed."
end
else
puts
"
Can't find routes.rb
"
puts
"
#{
routes_file
}
could not be found.
"
end
end
...
...
@@ -51,12 +51,12 @@ module AnnotateRoutes
new_content
=
strip_on_removal
(
content
,
header_position
)
new_text
=
new_content
.
join
(
"
\n
"
)
if
rewrite_contents
(
existing_text
,
new_text
)
puts
"
Removed annotations
from
#{
routes_file
}
."
puts
"
Annotations were removed
from
#{
routes_file
}
."
else
puts
"
#{
routes_file
}
unchanged
."
puts
"
#{
routes_file
}
was not changed (Annotation did not exist)
."
end
else
puts
"
Can't find routes.rb
"
puts
"
#{
routes_file
}
could not be found.
"
end
end
...
...
spec/lib/annotate/annotate_routes_spec.rb
View file @
7f8bf46a
...
...
@@ -3,9 +3,11 @@ require 'annotate/annotate_routes'
describe
AnnotateRoutes
do
ROUTE_FILE
=
'config/routes.rb'
.
freeze
ANNOTATION_ADDED
=
"
#{
ROUTE_FILE
}
annotated."
.
freeze
ANNOTATION_REMOVED
=
"Removed annotations from
#{
ROUTE_FILE
}
."
.
freeze
FILE_UNCHANGED
=
"
#{
ROUTE_FILE
}
unchanged."
.
freeze
MESSAGE_ANNOTATED
=
"
#{
ROUTE_FILE
}
was annotated."
.
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
=
[
'# encoding: UTF-8'
,
...
...
@@ -31,7 +33,7 @@ describe AnnotateRoutes do
it
'should check if routes.rb exists'
do
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
end
...
...
@@ -50,7 +52,7 @@ describe AnnotateRoutes do
expect
(
File
).
to
receive
(
:read
).
with
(
ROUTE_FILE
).
and_return
(
""
).
at_least
(
:once
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
ANNOTATION_ADD
ED
).
at_least
(
:once
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTAT
ED
).
at_least
(
:once
)
end
context
'without magic comments'
do
...
...
@@ -202,7 +204,7 @@ describe AnnotateRoutes do
expect
(
File
).
to
receive
(
:read
).
with
(
ROUTE_FILE
).
and_return
(
""
)
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
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
ANNOTATION_ADD
ED
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTAT
ED
)
AnnotateRoutes
.
do_annotations
end
...
...
@@ -211,7 +213,7 @@ describe AnnotateRoutes do
expect
(
File
).
to
receive
(
:read
).
with
(
ROUTE_FILE
).
and_return
(
""
)
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
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
ANNOTATION_ADD
ED
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTAT
ED
)
AnnotateRoutes
.
do_annotations
(
ignore_routes:
'my_route'
)
end
...
...
@@ -220,14 +222,14 @@ describe AnnotateRoutes do
expect
(
File
).
to
receive
(
:read
).
with
(
ROUTE_FILE
).
and_return
(
""
)
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
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
ANNOTATION_ADD
ED
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTAT
ED
)
AnnotateRoutes
.
do_annotations
(
position_in_routes:
'top'
)
end
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
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
FIL
E_UNCHANGED
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAG
E_UNCHANGED
)
AnnotateRoutes
.
do_annotations
end
...
...
@@ -240,7 +242,7 @@ describe AnnotateRoutes do
MAGIC_COMMENTS
.
each
do
|
magic_comment
|
expect
(
File
).
to
receive
(
:read
).
with
(
ROUTE_FILE
).
and_return
(
"
#{
magic_comment
}
\n
Something"
)
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
"
#{
magic_comment
}
\n\n
# == Route Map
\n
#
\n\n
Something
\n
"
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
ANNOTATION_ADD
ED
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTAT
ED
)
AnnotateRoutes
.
do_annotations
(
position_in_routes:
'top'
)
end
end
...
...
@@ -252,7 +254,7 @@ describe AnnotateRoutes do
MAGIC_COMMENTS
.
each
do
|
magic_comment
|
expect
(
File
).
to
receive
(
:read
).
with
(
ROUTE_FILE
).
and_return
(
"
#{
magic_comment
}
\n
Something"
)
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
"
#{
magic_comment
}
\n
Something
\n\n
# == Route Map
\n
#
\n
"
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
ANNOTATION_ADD
ED
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTAT
ED
)
AnnotateRoutes
.
do_annotations
(
position_in_routes:
'bottom'
)
end
end
...
...
@@ -261,7 +263,7 @@ describe AnnotateRoutes do
MAGIC_COMMENTS
.
each
do
|
magic_comment
|
expect
(
File
).
to
receive
(
:read
).
with
(
ROUTE_FILE
)
.
and_return
(
"
#{
magic_comment
}
\n\n
# == Route Map
\n
#
\n
"
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
FIL
E_UNCHANGED
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAG
E_UNCHANGED
)
AnnotateRoutes
.
do_annotations
end
...
...
@@ -274,7 +276,7 @@ describe AnnotateRoutes do
expect
(
File
).
to
receive
(
:exist?
).
with
(
ROUTE_FILE
).
and_return
(
true
)
expect
(
AnnotateRoutes
).
to
receive
(
:`
).
with
(
'rake routes'
).
and_return
(
"(in /bad/line)
\n
good line"
)
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
ANNOTATION_ADD
ED
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTAT
ED
)
end
it
'should annotate and add a newline!'
do
...
...
@@ -295,7 +297,7 @@ describe AnnotateRoutes do
expect
(
File
).
to
receive
(
:exist?
).
with
(
ROUTE_FILE
).
and_return
(
true
)
expect
(
AnnotateRoutes
).
to
receive
(
:`
).
with
(
'rake routes'
).
and_return
(
"another good line
\n
good line"
)
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
ANNOTATION_ADD
ED
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTAT
ED
)
end
it
'should annotate and add a newline!'
do
...
...
@@ -321,7 +323,7 @@ describe AnnotateRoutes do
before
(
:each
)
do
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
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
ANNOTATION
_REMOVED
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE
_REMOVED
)
end
it
'should remove trailing annotation and trim trailing newlines, but leave leading newlines alone'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment