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
dce2ac6c
Unverified
Commit
dce2ac6c
authored
Feb 25, 2020
by
Shu Fujita
Committed by
GitHub
Feb 25, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor test cases of AnnotateRoutes (#760)
This is the final completed version of refactoring AnnotateRoutes.
parent
47d4d4aa
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
277 additions
and
159 deletions
+277
-159
.rubocop_todo.yml
.rubocop_todo.yml
+4
-13
annotate_routes_spec.rb
spec/lib/annotate/annotate_routes_spec.rb
+273
-146
No files found.
.rubocop_todo.yml
View file @
dce2ac6c
# This configuration was generated by
# This configuration was generated by
# `rubocop --auto-gen-config`
# `rubocop --auto-gen-config`
# on 2020-02-13
18:10:52
+0900 using RuboCop version 0.68.1.
# on 2020-02-13
20:05:34
+0900 using RuboCop version 0.68.1.
# The point is for the user to remove these configuration records
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# Note that changes in the inspected code, or installation of new
...
@@ -64,14 +64,6 @@ Layout/ExtraSpacing:
...
@@ -64,14 +64,6 @@ Layout/ExtraSpacing:
-
'
lib/annotate/annotate_models.rb'
-
'
lib/annotate/annotate_models.rb'
-
'
lib/tasks/annotate_routes.rake'
-
'
lib/tasks/annotate_routes.rake'
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: aligned, indented, indented_relative_to_receiver
Layout/MultilineMethodCallIndentation
:
Exclude
:
-
'
spec/lib/annotate/annotate_routes_spec.rb'
# Offense count: 5
# Offense count: 5
# Cop supports --auto-correct.
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, IndentationWidth.
# Configuration parameters: EnforcedStyle, IndentationWidth.
...
@@ -221,7 +213,7 @@ Naming/AccessorMethodName:
...
@@ -221,7 +213,7 @@ Naming/AccessorMethodName:
Exclude
:
Exclude
:
-
'
lib/annotate.rb'
-
'
lib/annotate.rb'
# Offense count:
9
3
# Offense count:
10
3
# Configuration parameters: Blacklist.
# Configuration parameters: Blacklist.
# Blacklist: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
# Blacklist: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
Naming/HeredocDelimiterNaming
:
Naming/HeredocDelimiterNaming
:
...
@@ -478,7 +470,7 @@ Style/StderrPuts:
...
@@ -478,7 +470,7 @@ Style/StderrPuts:
-
'
lib/annotate.rb'
-
'
lib/annotate.rb'
-
'
lib/annotate/annotate_models.rb'
-
'
lib/annotate/annotate_models.rb'
# Offense count: 1
11
# Offense count: 1
07
# Cop supports --auto-correct.
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
# SupportedStyles: single_quotes, double_quotes
...
@@ -490,7 +482,6 @@ Style/StringLiterals:
...
@@ -490,7 +482,6 @@ Style/StringLiterals:
-
'
lib/tasks/annotate_models_migrate.rake'
-
'
lib/tasks/annotate_models_migrate.rake'
-
'
lib/tasks/annotate_routes.rake'
-
'
lib/tasks/annotate_routes.rake'
-
'
spec/lib/annotate/annotate_models_spec.rb'
-
'
spec/lib/annotate/annotate_models_spec.rb'
-
'
spec/lib/annotate/annotate_routes_spec.rb'
-
'
spec/lib/annotate/parser_spec.rb'
-
'
spec/lib/annotate/parser_spec.rb'
# Offense count: 1
# Offense count: 1
...
@@ -528,7 +519,7 @@ Style/UnneededPercentQ:
...
@@ -528,7 +519,7 @@ Style/UnneededPercentQ:
Exclude
:
Exclude
:
-
'
annotate.gemspec'
-
'
annotate.gemspec'
# Offense count: 3
46
# Offense count: 3
77
# Cop supports --auto-correct.
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
# URISchemes: http, https
...
...
spec/lib/annotate/annotate_routes_spec.rb
View file @
dce2ac6c
...
@@ -31,13 +31,30 @@ describe AnnotateRoutes do
...
@@ -31,13 +31,30 @@ describe AnnotateRoutes do
double
(
File
,
stubs
)
double
(
File
,
stubs
)
end
end
it
'should check if routes.rb exists'
do
describe
'.do_annotations'
do
expect
(
File
).
to
receive
(
:exist?
).
with
(
ROUTE_FILE
).
and_return
(
false
)
context
'When "config/routes.rb" does not exist'
do
before
:each
do
expect
(
File
).
to
receive
(
:exist?
).
with
(
ROUTE_FILE
).
and_return
(
false
).
once
end
it
'does not annotates any file'
do
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_NOT_FOUND
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_NOT_FOUND
)
AnnotateRoutes
.
do_annotations
AnnotateRoutes
.
do_annotations
end
end
end
context
'When "config/routes.rb" exists'
do
before
:each
do
expect
(
File
).
to
receive
(
:exist?
).
with
(
ROUTE_FILE
).
and_return
(
true
).
once
expect
(
File
).
to
receive
(
:read
).
with
(
ROUTE_FILE
).
and_return
(
route_file_content
).
once
expect
(
AnnotateRoutes
).
to
receive
(
:`
).
with
(
'rake routes'
).
and_return
(
rake_routes_result
).
once
end
describe
'Annotate#example'
do
context
'When the result of `rake routes` is present'
do
context
'When the result of `rake routes` does not contain Rake version'
do
context
'When the file does not contain magic comment'
do
let
:rake_routes_result
do
let
:rake_routes_result
do
<<-
EOS
<<-
EOS
Prefix Verb URI Pattern Controller#Action
Prefix Verb URI Pattern Controller#Action
...
@@ -47,21 +64,14 @@ describe AnnotateRoutes do
...
@@ -47,21 +64,14 @@ describe AnnotateRoutes do
EOS
EOS
end
end
before
(
:each
)
do
let
:route_file_content
do
expect
(
File
).
to
receive
(
:exist?
).
with
(
ROUTE_FILE
).
and_return
(
true
).
at_least
(
:once
)
''
expect
(
File
).
to
receive
(
:read
).
with
(
ROUTE_FILE
).
and_return
(
""
).
at_least
(
:once
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTATED
).
at_least
(
:once
)
end
context
'without magic comments'
do
before
(
:each
)
do
expect
(
AnnotateRoutes
).
to
receive
(
:`
).
with
(
'rake routes'
).
and_return
(
rake_routes_result
)
end
end
it
'annotate normal'
do
context
'When the file does not contain annotation yet'
do
expected_result
=
<<~
EOS
context
'When no option is passed'
do
let
:expected_result
do
<<~
EOS
# == Route Map
# == Route Map
#
#
...
@@ -70,15 +80,20 @@ describe AnnotateRoutes do
...
@@ -70,15 +80,20 @@ describe AnnotateRoutes do
# myaction2 POST /url2(.:format) mycontroller2#action
# myaction2 POST /url2(.:format) mycontroller2#action
# myaction3 DELETE|GET /url3(.:format) mycontroller3#action
# myaction3 DELETE|GET /url3(.:format) mycontroller3#action
EOS
EOS
end
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
)
it
'annotates normally'
do
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
)
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
).
once
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
).
once
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTATED
).
once
AnnotateRoutes
.
do_annotations
AnnotateRoutes
.
do_annotations
end
end
end
it
'annotate markdown'
do
context
'When the option "format_markdown" is passed'
do
expected_result
=
<<~
EOS
let
:expected_result
do
<<~
EOS
# ## Route Map
# ## Route Map
#
#
...
@@ -88,15 +103,20 @@ describe AnnotateRoutes do
...
@@ -88,15 +103,20 @@ describe AnnotateRoutes do
# myaction2 | POST | /url2(.:format) | mycontroller2#action
# myaction2 | POST | /url2(.:format) | mycontroller2#action
# myaction3 | DELETE-GET | /url3(.:format) | mycontroller3#action
# myaction3 | DELETE-GET | /url3(.:format) | mycontroller3#action
EOS
EOS
end
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
)
it
'annotates in Markdown format'
do
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
)
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
).
once
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
).
once
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTATED
).
once
AnnotateRoutes
.
do_annotations
(
format_markdown:
true
)
AnnotateRoutes
.
do_annotations
(
format_markdown:
true
)
end
end
end
it
'wraps annotation if wrapper is specified'
do
context
'When the options "wrapper_open" and "wrapper_close" are passed'
do
expected_result
=
<<~
EOS
let
:expected_result
do
<<~
EOS
# START
# START
# == Route Map
# == Route Map
...
@@ -107,19 +127,41 @@ describe AnnotateRoutes do
...
@@ -107,19 +127,41 @@ describe AnnotateRoutes do
# myaction3 DELETE|GET /url3(.:format) mycontroller3#action
# myaction3 DELETE|GET /url3(.:format) mycontroller3#action
# END
# END
EOS
EOS
end
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
)
it
'annotates and wraps annotation with specified words'
do
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
)
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
).
once
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
).
once
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTATED
).
once
AnnotateRoutes
.
do_annotations
(
wrapper_open:
'START'
,
wrapper_close:
'END'
)
AnnotateRoutes
.
do_annotations
(
wrapper_open:
'START'
,
wrapper_close:
'END'
)
end
end
end
end
end
end
context
'file with magic comments'
do
context
'When the file contains magic comments'
do
it
'should not remove magic comments'
do
MAGIC_COMMENTS
.
each
do
|
magic_comment
|
MAGIC_COMMENTS
.
each
do
|
magic_comment
|
expected_result
=
<<~
EOS
describe
"magic comment:
#{
magic_comment
.
inspect
}
"
do
let
:route_file_content
do
<<~
EOS
#{
magic_comment
}
EOS
end
let
:rake_routes_result
do
<<-
EOS
Prefix Verb URI Pattern Controller#Action
myaction1 GET /url1(.:format) mycontroller1#action
myaction2 POST /url2(.:format) mycontroller2#action
myaction3 DELETE|GET /url3(.:format) mycontroller3#action
EOS
end
context
'When the file does not contain annotation yet'
do
context
'When no option is passed'
do
let
:expected_result
do
<<~
EOS
#{
magic_comment
}
#{
magic_comment
}
# == Route Map
# == Route Map
...
@@ -129,21 +171,20 @@ describe AnnotateRoutes do
...
@@ -129,21 +171,20 @@ describe AnnotateRoutes do
# myaction2 POST /url2(.:format) mycontroller2#action
# myaction2 POST /url2(.:format) mycontroller2#action
# myaction3 DELETE|GET /url3(.:format) mycontroller3#action
# myaction3 DELETE|GET /url3(.:format) mycontroller3#action
EOS
EOS
end
expect
(
AnnotateRoutes
).
to
receive
(
:`
).
with
(
'rake routes'
)
it
'annotates normally'
do
.
and_return
(
"
#{
magic_comment
}
\n
#{
rake_routes_result
}
"
)
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
).
once
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
).
once
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTATED
).
once
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
)
AnnotateRoutes
.
do_annotations
AnnotateRoutes
.
do_annotations
end
end
end
end
it
'annotate markdown'
do
context
'When the option "format_markdown" is passed'
do
MAGIC_COMMENTS
.
each
do
|
magic_comment
|
let
:expected_result
do
expected_result
=
<<~
EOS
<<~
EOS
#{
magic_comment
}
#{
magic_comment
}
# ## Route Map
# ## Route Map
...
@@ -154,21 +195,20 @@ describe AnnotateRoutes do
...
@@ -154,21 +195,20 @@ describe AnnotateRoutes do
# myaction2 | POST | /url2(.:format) | mycontroller2#action
# myaction2 | POST | /url2(.:format) | mycontroller2#action
# myaction3 | DELETE-GET | /url3(.:format) | mycontroller3#action
# myaction3 | DELETE-GET | /url3(.:format) | mycontroller3#action
EOS
EOS
end
expect
(
AnnotateRoutes
).
to
receive
(
:`
).
with
(
'rake routes'
)
it
'annotates in Markdown format'
do
.
and_return
(
"
#{
magic_comment
}
\n
#{
rake_routes_result
}
"
)
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
).
once
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
).
once
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTATED
).
once
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
)
AnnotateRoutes
.
do_annotations
(
format_markdown:
true
)
AnnotateRoutes
.
do_annotations
(
format_markdown:
true
)
end
end
end
end
it
'wraps annotation if wrapper is specified'
do
context
'When the options "wrapper_open" and "wrapper_close" are passed'
do
MAGIC_COMMENTS
.
each
do
|
magic_comment
|
let
:expected_result
do
expected_result
=
<<~
EOS
<<~
EOS
#{
magic_comment
}
#{
magic_comment
}
# START
# START
...
@@ -180,106 +220,23 @@ describe AnnotateRoutes do
...
@@ -180,106 +220,23 @@ describe AnnotateRoutes do
# myaction3 DELETE|GET /url3(.:format) mycontroller3#action
# myaction3 DELETE|GET /url3(.:format) mycontroller3#action
# END
# END
EOS
EOS
expect
(
AnnotateRoutes
).
to
receive
(
:`
).
with
(
'rake routes'
)
.
and_return
(
"
#{
magic_comment
}
\n
#{
rake_routes_result
}
"
)
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
)
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
)
AnnotateRoutes
.
do_annotations
(
wrapper_open:
'START'
,
wrapper_close:
'END'
)
end
end
end
end
describe
'When adding'
do
before
(
:each
)
do
expect
(
File
).
to
receive
(
:exist?
).
with
(
ROUTE_FILE
)
.
and_return
(
true
).
at_least
(
:once
)
expect
(
AnnotateRoutes
).
to
receive
(
:`
).
with
(
'rake routes'
)
.
and_return
(
''
).
at_least
(
:once
)
end
it
'should insert annotations if file does not contain annotations'
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
(
MESSAGE_ANNOTATED
)
AnnotateRoutes
.
do_annotations
end
it
'should insert annotations if file does not contain annotations and ignore routes'
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
(
MESSAGE_ANNOTATED
)
AnnotateRoutes
.
do_annotations
(
ignore_routes:
'my_route'
)
end
it
'should insert annotations if file does not contain annotations and position top'
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
(
MESSAGE_ANNOTATED
)
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
(
MESSAGE_UNCHANGED
)
AnnotateRoutes
.
do_annotations
end
end
context
'file with magic comments'
do
it
'annotates and wraps annotation with specified words'
do
it
'leaves magic comment on top, adds an empty line between magic comment and annotation (position_in_routes :top)'
do
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
).
once
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
)
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
).
once
.
and_yield
(
mock_file
).
at_least
(
:once
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTATED
).
once
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
(
MESSAGE_ANNOTATED
)
AnnotateRoutes
.
do_annotations
(
position_in_routes:
'top'
)
end
end
it
'leaves magic comment on top, adds an empty line between magic comment and annotation (position_in_routes :bottom)'
do
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
)
.
and_yield
(
mock_file
).
at_least
(
:once
)
MAGIC_COMMENTS
.
each
do
|
magic_comment
|
AnnotateRoutes
.
do_annotations
(
wrapper_open:
'START'
,
wrapper_close:
'END'
)
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
(
MESSAGE_ANNOTATED
)
AnnotateRoutes
.
do_annotations
(
position_in_routes:
'bottom'
)
end
end
end
end
it
'skips annotations if file does already contain annotation'
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
(
MESSAGE_UNCHANGED
)
AnnotateRoutes
.
do_annotations
end
end
end
end
end
end
end
end
describe
'As for Rake versions'
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
(
File
).
to
receive
(
:read
).
with
(
ROUTE_FILE
).
and_return
(
route_file_content
)
expect
(
AnnotateRoutes
).
to
receive
(
:`
).
with
(
'rake routes'
).
and_return
(
rake_routes_result
)
end
end
context
'When the result of `rake routes` contains Rake version'
do
context
'with older Rake versions'
do
context
'with older Rake versions'
do
let
:rake_routes_result
do
let
:rake_routes_result
do
<<~
EOS
.
chomp
<<~
EOS
.
chomp
...
@@ -308,8 +265,9 @@ describe AnnotateRoutes do
...
@@ -308,8 +265,9 @@ describe AnnotateRoutes do
end
end
it
'annotates with an empty line'
do
it
'annotates with an empty line'
do
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
)
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
).
once
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTATED
)
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
).
once
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTATED
).
once
AnnotateRoutes
.
do_annotations
AnnotateRoutes
.
do_annotations
end
end
...
@@ -335,8 +293,9 @@ describe AnnotateRoutes do
...
@@ -335,8 +293,9 @@ describe AnnotateRoutes do
end
end
it
'annotates without an empty line'
do
it
'annotates without an empty line'
do
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
)
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
).
once
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTATED
)
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
).
once
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTATED
).
once
AnnotateRoutes
.
do_annotations
AnnotateRoutes
.
do_annotations
end
end
...
@@ -373,8 +332,9 @@ describe AnnotateRoutes do
...
@@ -373,8 +332,9 @@ describe AnnotateRoutes do
end
end
it
'annotates with an empty line'
do
it
'annotates with an empty line'
do
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
)
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
).
once
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTATED
)
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
).
once
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTATED
).
once
AnnotateRoutes
.
do_annotations
AnnotateRoutes
.
do_annotations
end
end
...
@@ -402,8 +362,9 @@ describe AnnotateRoutes do
...
@@ -402,8 +362,9 @@ describe AnnotateRoutes do
end
end
it
'annotates without an empty line'
do
it
'annotates without an empty line'
do
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
)
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
).
once
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTATED
)
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
).
once
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTATED
).
once
AnnotateRoutes
.
do_annotations
AnnotateRoutes
.
do_annotations
end
end
...
@@ -422,14 +383,180 @@ describe AnnotateRoutes do
...
@@ -422,14 +383,180 @@ describe AnnotateRoutes do
end
end
it
'annotates with the timestamp and an empty line'
do
it
'annotates with the timestamp and an empty line'
do
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
)
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
).
once
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTATED
)
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
).
once
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTATED
).
once
AnnotateRoutes
.
do_annotations
timestamp:
true
AnnotateRoutes
.
do_annotations
timestamp:
true
end
end
end
end
end
end
end
end
end
context
'When the result of `rake routes` is blank'
do
let
:rake_routes_result
do
''
end
context
'When the file does not contain magic comment'
do
context
'When the file does not contain annotation yet'
do
let
:route_file_content
do
''
end
context
'When no option is specified'
do
let
:expected_result
do
<<~
EOS
# == Route Map
#
EOS
end
it
'inserts annotations'
do
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
).
once
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
).
once
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTATED
).
once
AnnotateRoutes
.
do_annotations
end
end
context
'When the option "ignore_routes" is specified'
do
let
:expected_result
do
<<~
EOS
# == Route Map
#
EOS
end
it
'inserts annotations'
do
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
).
once
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
).
once
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTATED
).
once
AnnotateRoutes
.
do_annotations
(
ignore_routes:
'my_route'
)
end
end
context
'When the option "position_in_routes" is specified as "top"'
do
let
:expected_result
do
<<~
EOS
# == Route Map
#
EOS
end
it
'inserts annotations'
do
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
).
once
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
).
once
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTATED
).
once
AnnotateRoutes
.
do_annotations
(
position_in_routes:
'top'
)
end
end
end
context
'When the file already contains annotation'
do
context
'When no option is specified'
do
let
:route_file_content
do
<<~
EOS
# == Route Map
#
EOS
end
it
'should skip annotations if file does already contain annotation'
do
expect
(
File
).
not_to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
)
expect
(
mock_file
).
not_to
receive
(
:puts
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_UNCHANGED
).
once
AnnotateRoutes
.
do_annotations
end
end
end
end
context
'When the file contains magic comments'
do
MAGIC_COMMENTS
.
each
do
|
magic_comment
|
describe
"magic comment:
#{
magic_comment
.
inspect
}
"
do
let
:route_file_content
do
<<~
EOS
#{
magic_comment
}
Something
EOS
end
context
'When the file does not contain annotation yet'
do
context
'When the option "position_in_routes" is specified as "top"'
do
let
:expected_result
do
<<~
EOS
#{
magic_comment
}
# == Route Map
#
Something
EOS
end
it
'leaves magic comment on top and adds an empty line between magic comment and annotation'
do
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
).
once
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
).
once
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTATED
).
once
AnnotateRoutes
.
do_annotations
(
position_in_routes:
'top'
)
end
end
context
'When the option "position_in_routes" is specified as "bottom"'
do
let
:expected_result
do
<<~
EOS
#{
magic_comment
}
Something
# == Route Map
#
EOS
end
it
'leaves magic comment on top and adds an empty line between magic comment and annotation'
do
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
).
once
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
).
once
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTATED
).
once
AnnotateRoutes
.
do_annotations
(
position_in_routes:
'bottom'
)
end
end
end
context
'When the file already contains annotation'
do
let
:route_file_content
do
<<~
EOS
#{
magic_comment
}
# == Route Map
#
EOS
end
it
'skips annotations'
do
expect
(
File
).
not_to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
)
expect
(
mock_file
).
not_to
receive
(
:puts
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_UNCHANGED
).
once
AnnotateRoutes
.
do_annotations
end
end
end
end
end
end
end
end
describe
'.remove_annotations'
do
describe
'.remove_annotations'
do
before
:each
do
before
:each
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