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
d902dc4c
Unverified
Commit
d902dc4c
authored
Feb 13, 2020
by
Shu Fujita
Committed by
GitHub
Feb 13, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor test cases of AnnotateRoutes as for Rake versions (#754)
Refactor test cases for entire rewrite in the future.
parent
ec0b3b61
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
140 additions
and
28 deletions
+140
-28
.rubocop_todo.yml
.rubocop_todo.yml
+3
-3
annotate_routes_spec.rb
spec/lib/annotate/annotate_routes_spec.rb
+137
-25
No files found.
.rubocop_todo.yml
View file @
d902dc4c
# This configuration was generated by
# This configuration was generated by
# `rubocop --auto-gen-config`
# `rubocop --auto-gen-config`
# on 2020-02-
05 17:13:49 -10
00 using RuboCop version 0.68.1.
# on 2020-02-
12 18:43:06 +09
00 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
...
@@ -221,7 +221,7 @@ Naming/AccessorMethodName:
...
@@ -221,7 +221,7 @@ Naming/AccessorMethodName:
Exclude
:
Exclude
:
-
'
lib/annotate.rb'
-
'
lib/annotate.rb'
# Offense count:
82
# Offense count:
93
# 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
:
...
@@ -528,7 +528,7 @@ Style/UnneededPercentQ:
...
@@ -528,7 +528,7 @@ Style/UnneededPercentQ:
Exclude
:
Exclude
:
-
'
annotate.gemspec'
-
'
annotate.gemspec'
# Offense count: 3
53
# Offense count: 3
44
# 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 @
d902dc4c
...
@@ -271,53 +271,165 @@ describe AnnotateRoutes do
...
@@ -271,53 +271,165 @@ describe AnnotateRoutes do
end
end
end
end
describe
'
When adding with olde
r Rake versions'
do
describe
'
As fo
r Rake versions'
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
(
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
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTATED
)
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
it
'should annotate and add a newline!'
do
context
'with older Rake versions'
do
expect
(
File
).
to
receive
(
:read
).
with
(
ROUTE_FILE
).
and_return
(
"ActionController::Routing...
\n
foo"
)
let
:rake_routes_result
do
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
/ActionController::Routing...\nfoo\n\n# == Route Map\n#\n# good line\n/
)
<<~
EOS
.
chomp
AnnotateRoutes
.
do_annotations
(in /bad/line)
good line
EOS
end
context
'When the route file does not end with an empty line'
do
let
:route_file_content
do
<<~
EOS
.
chomp
ActionController::Routing...
foo
EOS
end
let
:expected_result
do
<<~
EOS
ActionController::Routing...
foo
# == Route Map
#
# good line
EOS
end
end
it
'should not add a newline if there are empty lines'
do
it
'annotates with an empty line'
do
expect
(
File
).
to
receive
(
:read
).
with
(
ROUTE_FILE
).
and_return
(
"ActionController::Routing...
\n
foo
\n
"
)
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
)
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
/ActionController::Routing...\nfoo\n\n# == Route Map\n#\n# good line\n/
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTATED
)
AnnotateRoutes
.
do_annotations
AnnotateRoutes
.
do_annotations
end
end
end
end
describe
'When adding with newer Rake versions'
do
context
'When the route file ends with an empty line'
do
before
(
:each
)
do
let
:route_file_content
do
expect
(
File
).
to
receive
(
:exist?
).
with
(
ROUTE_FILE
).
and_return
(
true
)
<<~
EOS
expect
(
AnnotateRoutes
).
to
receive
(
:`
).
with
(
'rake routes'
).
and_return
(
"another good line
\n
good line"
)
ActionController::Routing...
expect
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
)
foo
EOS
end
let
:expected_result
do
<<~
EOS
ActionController::Routing...
foo
# == Route Map
#
# good line
EOS
end
it
'annotates without an empty line'
do
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTATED
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTATED
)
AnnotateRoutes
.
do_annotations
end
end
end
context
'with newer Rake versions'
do
let
:rake_routes_result
do
<<~
EOS
.
chomp
another good line
good line
EOS
end
context
'When the route file does not end with an empty line'
do
context
'When no option is passed'
do
let
:route_file_content
do
<<~
EOS
.
chomp
ActionController::Routing...
foo
EOS
end
let
:expected_result
do
<<~
EOS
ActionController::Routing...
foo
# == Route Map
#
# another good line
# good line
EOS
end
end
it
'should annotate and add a newline!'
do
it
'annotates with an empty line'
do
expect
(
File
).
to
receive
(
:read
).
with
(
ROUTE_FILE
).
and_return
(
"ActionController::Routing...
\n
foo"
)
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
)
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
/ActionController::Routing...\nfoo\n\n# == Route Map\n#\n# another good line\n# good line\n/
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTATED
)
AnnotateRoutes
.
do_annotations
AnnotateRoutes
.
do_annotations
end
end
end
end
context
'When the route file ends with an empty line'
do
let
:route_file_content
do
<<~
EOS
ActionController::Routing...
foo
EOS
end
let
:expected_result
do
<<~
EOS
ActionController::Routing...
foo
# == Route Map
#
# another good line
# good line
EOS
end
it
'annotates without an empty line'
do
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTATED
)
it
'should not add a newline if there are empty lines'
do
expect
(
File
).
to
receive
(
:read
).
with
(
ROUTE_FILE
).
and_return
(
"ActionController::Routing...
\n
foo
\n
"
)
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
/ActionController::Routing...\nfoo\n\n# == Route Map\n#\n# another good line\n# good line\n/
)
AnnotateRoutes
.
do_annotations
AnnotateRoutes
.
do_annotations
end
end
end
context
'When option "timestamp" is passed'
do
let
:route_file_content
do
<<~
EOS
.
chomp
ActionController::Routing...
foo
EOS
end
let
:expected_result
do
/ActionController::Routing...\nfoo\n\n# == Route Map \(Updated \d{4}-\d{2}-\d{2} \d{2}:\d{2}\)\n#\n# another good line\n# good line\n/
end
it
'annotates with the timestamp and an empty line'
do
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
)
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_ANNOTATED
)
it
'should add a timestamp when :timestamp is passed'
do
expect
(
File
).
to
receive
(
:read
).
with
(
ROUTE_FILE
).
and_return
(
"ActionController::Routing...
\n
foo"
)
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
/ActionController::Routing...\nfoo\n\n# == Route Map \(Updated \d{4}-\d{2}-\d{2} \d{2}:\d{2}\)\n#\n# another good line\n# good line\n/
)
AnnotateRoutes
.
do_annotations
timestamp:
true
AnnotateRoutes
.
do_annotations
timestamp:
true
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