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
d4c04ff7
Unverified
Commit
d4c04ff7
authored
Feb 06, 2020
by
Shu Fujita
Committed by
GitHub
Feb 05, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor test cases for AnnotateRoutes.remove_annotations (#748)
Refactor of test cases for AnnotateRoutes.remove_annotations after #736.
parent
3be824bb
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
20 deletions
+40
-20
annotate_routes_spec.rb
spec/lib/annotate/annotate_routes_spec.rb
+40
-20
No files found.
spec/lib/annotate/annotate_routes_spec.rb
View file @
d4c04ff7
...
...
@@ -319,15 +319,16 @@ describe AnnotateRoutes do
end
end
describe
'
When removing
'
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
(
MESSAGE_REMOVED
)
describe
'
.remove_annotations
'
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
(
File
).
to
receive
(
:open
).
with
(
ROUTE_FILE
,
'wb'
).
and_yield
(
mock_file
).
once
end
it
'should remove trailing annotation and trim trailing newlines, but leave leading newlines alone'
do
route_file_content
=
<<~
EOS
context
'When trailing annotation exists'
do
let
:route_file_content
do
<<~
EOS
...
...
@@ -340,22 +341,29 @@ describe AnnotateRoutes do
# another good line
# good line
EOS
end
expected_result
=
<<~
EOS
let
:expected_result
do
<<~
EOS
ActionController::Routing...
foo
EOS
end
it
'removes trailing annotation and trim trailing newlines, but leave leading newlines alone'
do
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
).
once
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_REMOVED
).
once
expect
(
File
).
to
receive
(
:read
).
with
(
ROUTE_FILE
).
and_return
(
route_file_content
)
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
)
AnnotateRoutes
.
remove_annotations
end
end
it
'should remove prepended annotation and trim leading newlines, but leave trailing newlines alone'
do
route_file_content
=
<<~
EOS
context
'When prepended annotation exists'
do
let
:route_file_content
do
<<~
EOS
# == Route Map
#
# another good line
...
...
@@ -371,8 +379,10 @@ describe AnnotateRoutes do
EOS
end
expected_result
=
<<~
EOS
let
:expected_result
do
<<~
EOS
Rails.application.routes.draw do
root 'root#index'
end
...
...
@@ -380,14 +390,19 @@ describe AnnotateRoutes do
EOS
end
it
'removes prepended annotation and trim leading newlines, but leave trailing newlines alone'
do
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
).
once
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_REMOVED
).
once
expect
(
File
).
to
receive
(
:read
).
with
(
ROUTE_FILE
).
and_return
(
route_file_content
)
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
)
AnnotateRoutes
.
remove_annotations
end
end
it
'should not remove custom comments above route map'
do
route_file_content
=
<<~
EOS
context
'When custom comments are above route map'
do
let
:route_file_content
do
<<~
EOS
# My comment
# == Route Map
#
...
...
@@ -397,18 +412,23 @@ describe AnnotateRoutes do
root 'root#index'
end
EOS
end
expected_result
=
<<~
EOS
let
:expected_result
do
<<~
EOS
# My comment
Rails.application.routes.draw do
root 'root#index'
end
EOS
end
expect
(
File
).
to
receive
(
:read
).
with
(
ROUTE_FILE
).
and_return
(
route_file_content
)
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
)
it
'does not remove custom comments above route map'
do
expect
(
mock_file
).
to
receive
(
:puts
).
with
(
expected_result
).
once
expect
(
AnnotateRoutes
).
to
receive
(
:puts
).
with
(
MESSAGE_REMOVED
).
once
AnnotateRoutes
.
remove_annotations
end
end
end
end
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