Skip to content

Commit 6de2d6e

Browse files
committed
Make purpose of test cases more clear
1 parent f5cff71 commit 6de2d6e

File tree

1 file changed

+143
-141
lines changed

1 file changed

+143
-141
lines changed

spec/lib/annotate/annotate_routes_spec.rb

Lines changed: 143 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -45,188 +45,190 @@
4545
end
4646

4747
context 'When "config/routes.rb" exists' do
48-
before(:each) do
48+
before :each do
4949
expect(File).to receive(:exist?).with(ROUTE_FILE).and_return(true).once
5050
expect(File).to receive(:read).with(ROUTE_FILE).and_return(route_file_content).once
5151

5252
expect(AnnotateRoutes).to receive(:`).with('rake routes').and_return(rake_routes_result).once
5353
end
5454

5555
context 'When the result of `rake routes` is present' do
56-
context 'When the file does not contain magic comment' do
57-
let :rake_routes_result do
58-
<<-EOS
56+
context 'When the result of `rake routes` does not contain Rake version' do
57+
context 'When the file does not contain magic comment' do
58+
let :rake_routes_result do
59+
<<-EOS
5960
Prefix Verb URI Pattern Controller#Action
6061
myaction1 GET /url1(.:format) mycontroller1#action
6162
myaction2 POST /url2(.:format) mycontroller2#action
6263
myaction3 DELETE|GET /url3(.:format) mycontroller3#action
63-
EOS
64-
end
64+
EOS
65+
end
6566

66-
let :route_file_content do
67-
''
68-
end
67+
let :route_file_content do
68+
''
69+
end
6970

70-
context 'When the file does not contain annotation yet' do
71-
context 'When no option is passed' do
72-
let :expected_result do
73-
<<~EOS
71+
context 'When the file does not contain annotation yet' do
72+
context 'When no option is passed' do
73+
let :expected_result do
74+
<<~EOS
7475
75-
# == Route Map
76-
#
77-
# Prefix Verb URI Pattern Controller#Action
78-
# myaction1 GET /url1(.:format) mycontroller1#action
79-
# myaction2 POST /url2(.:format) mycontroller2#action
80-
# myaction3 DELETE|GET /url3(.:format) mycontroller3#action
81-
EOS
82-
end
76+
# == Route Map
77+
#
78+
# Prefix Verb URI Pattern Controller#Action
79+
# myaction1 GET /url1(.:format) mycontroller1#action
80+
# myaction2 POST /url2(.:format) mycontroller2#action
81+
# myaction3 DELETE|GET /url3(.:format) mycontroller3#action
82+
EOS
83+
end
8384

84-
it 'annotates normally' do
85-
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once
86-
expect(mock_file).to receive(:puts).with(expected_result).once
87-
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once
85+
it 'annotates normally' do
86+
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once
87+
expect(mock_file).to receive(:puts).with(expected_result).once
88+
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once
8889

89-
AnnotateRoutes.do_annotations
90+
AnnotateRoutes.do_annotations
91+
end
9092
end
91-
end
9293

93-
context 'When the option "format_markdown" is passed' do
94-
let :expected_result do
95-
<<~EOS
94+
context 'When the option "format_markdown" is passed' do
95+
let :expected_result do
96+
<<~EOS
9697
97-
# ## Route Map
98-
#
99-
# Prefix | Verb | URI Pattern | Controller#Action
100-
# --------- | ---------- | --------------- | --------------------
101-
# myaction1 | GET | /url1(.:format) | mycontroller1#action
102-
# myaction2 | POST | /url2(.:format) | mycontroller2#action
103-
# myaction3 | DELETE-GET | /url3(.:format) | mycontroller3#action
104-
EOS
105-
end
98+
# ## Route Map
99+
#
100+
# Prefix | Verb | URI Pattern | Controller#Action
101+
# --------- | ---------- | --------------- | --------------------
102+
# myaction1 | GET | /url1(.:format) | mycontroller1#action
103+
# myaction2 | POST | /url2(.:format) | mycontroller2#action
104+
# myaction3 | DELETE-GET | /url3(.:format) | mycontroller3#action
105+
EOS
106+
end
106107

107-
it 'annotates in Markdown format' do
108-
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once
109-
expect(mock_file).to receive(:puts).with(expected_result).once
110-
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once
108+
it 'annotates in Markdown format' do
109+
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once
110+
expect(mock_file).to receive(:puts).with(expected_result).once
111+
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once
111112

112-
AnnotateRoutes.do_annotations(format_markdown: true)
113+
AnnotateRoutes.do_annotations(format_markdown: true)
114+
end
113115
end
114-
end
115116

116-
context 'When the options "wrapper_open" and "wrapper_close" are passed' do
117-
let :expected_result do
118-
<<~EOS
117+
context 'When the options "wrapper_open" and "wrapper_close" are passed' do
118+
let :expected_result do
119+
<<~EOS
119120
120-
# START
121-
# == Route Map
122-
#
123-
# Prefix Verb URI Pattern Controller#Action
124-
# myaction1 GET /url1(.:format) mycontroller1#action
125-
# myaction2 POST /url2(.:format) mycontroller2#action
126-
# myaction3 DELETE|GET /url3(.:format) mycontroller3#action
127-
# END
128-
EOS
129-
end
121+
# START
122+
# == Route Map
123+
#
124+
# Prefix Verb URI Pattern Controller#Action
125+
# myaction1 GET /url1(.:format) mycontroller1#action
126+
# myaction2 POST /url2(.:format) mycontroller2#action
127+
# myaction3 DELETE|GET /url3(.:format) mycontroller3#action
128+
# END
129+
EOS
130+
end
130131

131-
it 'annotates and wraps annotation with specified words' do
132-
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once
133-
expect(mock_file).to receive(:puts).with(expected_result).once
134-
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once
132+
it 'annotates and wraps annotation with specified words' do
133+
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once
134+
expect(mock_file).to receive(:puts).with(expected_result).once
135+
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once
135136

136-
AnnotateRoutes.do_annotations(wrapper_open: 'START', wrapper_close: 'END')
137+
AnnotateRoutes.do_annotations(wrapper_open: 'START', wrapper_close: 'END')
138+
end
137139
end
138140
end
139141
end
140-
end
141142

142-
context 'When the file contains magic comments' do
143-
MAGIC_COMMENTS.each do |magic_comment|
144-
describe "magic comment: #{magic_comment.inspect}" do
145-
let :route_file_content do
146-
<<~EOS
147-
#{magic_comment}
148-
EOS
149-
end
143+
context 'When the file contains magic comments' do
144+
MAGIC_COMMENTS.each do |magic_comment|
145+
describe "magic comment: #{magic_comment.inspect}" do
146+
let :route_file_content do
147+
<<~EOS
148+
#{magic_comment}
149+
EOS
150+
end
150151

151-
let :rake_routes_result do
152-
<<-EOS
152+
let :rake_routes_result do
153+
<<-EOS
153154
Prefix Verb URI Pattern Controller#Action
154155
myaction1 GET /url1(.:format) mycontroller1#action
155156
myaction2 POST /url2(.:format) mycontroller2#action
156157
myaction3 DELETE|GET /url3(.:format) mycontroller3#action
157-
EOS
158-
end
159-
160-
context 'When the file does not contain annotation yet' do
161-
context 'When no option is passed' do
162-
let :expected_result do
163-
<<~EOS
164-
#{magic_comment}
165-
166-
# == Route Map
167-
#
168-
# Prefix Verb URI Pattern Controller#Action
169-
# myaction1 GET /url1(.:format) mycontroller1#action
170-
# myaction2 POST /url2(.:format) mycontroller2#action
171-
# myaction3 DELETE|GET /url3(.:format) mycontroller3#action
172-
EOS
173-
end
174-
175-
it 'annotates normally' do
176-
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once
177-
expect(mock_file).to receive(:puts).with(expected_result).once
178-
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once
179-
180-
AnnotateRoutes.do_annotations
181-
end
158+
EOS
182159
end
183160

184-
context 'When the option "format_markdown" is passed' do
185-
let :expected_result do
186-
<<~EOS
187-
#{magic_comment}
188-
189-
# ## Route Map
190-
#
191-
# Prefix | Verb | URI Pattern | Controller#Action
192-
# --------- | ---------- | --------------- | --------------------
193-
# myaction1 | GET | /url1(.:format) | mycontroller1#action
194-
# myaction2 | POST | /url2(.:format) | mycontroller2#action
195-
# myaction3 | DELETE-GET | /url3(.:format) | mycontroller3#action
196-
EOS
197-
end
198-
199-
it 'annotates in Markdown format' do
200-
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once
201-
expect(mock_file).to receive(:puts).with(expected_result).once
202-
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once
203-
204-
AnnotateRoutes.do_annotations(format_markdown: true)
161+
context 'When the file does not contain annotation yet' do
162+
context 'When no option is passed' do
163+
let :expected_result do
164+
<<~EOS
165+
#{magic_comment}
166+
167+
# == Route Map
168+
#
169+
# Prefix Verb URI Pattern Controller#Action
170+
# myaction1 GET /url1(.:format) mycontroller1#action
171+
# myaction2 POST /url2(.:format) mycontroller2#action
172+
# myaction3 DELETE|GET /url3(.:format) mycontroller3#action
173+
EOS
174+
end
175+
176+
it 'annotates normally' do
177+
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once
178+
expect(mock_file).to receive(:puts).with(expected_result).once
179+
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once
180+
181+
AnnotateRoutes.do_annotations
182+
end
205183
end
206-
end
207-
208-
context 'When the options "wrapper_open" and "wrapper_close" are passed' do
209-
let :expected_result do
210-
<<~EOS
211-
#{magic_comment}
212184

213-
# START
214-
# == Route Map
215-
#
216-
# Prefix Verb URI Pattern Controller#Action
217-
# myaction1 GET /url1(.:format) mycontroller1#action
218-
# myaction2 POST /url2(.:format) mycontroller2#action
219-
# myaction3 DELETE|GET /url3(.:format) mycontroller3#action
220-
# END
221-
EOS
185+
context 'When the option "format_markdown" is passed' do
186+
let :expected_result do
187+
<<~EOS
188+
#{magic_comment}
189+
190+
# ## Route Map
191+
#
192+
# Prefix | Verb | URI Pattern | Controller#Action
193+
# --------- | ---------- | --------------- | --------------------
194+
# myaction1 | GET | /url1(.:format) | mycontroller1#action
195+
# myaction2 | POST | /url2(.:format) | mycontroller2#action
196+
# myaction3 | DELETE-GET | /url3(.:format) | mycontroller3#action
197+
EOS
198+
end
199+
200+
it 'annotates in Markdown format' do
201+
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once
202+
expect(mock_file).to receive(:puts).with(expected_result).once
203+
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once
204+
205+
AnnotateRoutes.do_annotations(format_markdown: true)
206+
end
222207
end
223208

224-
it 'annotates and wraps annotation with specified words' do
225-
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once
226-
expect(mock_file).to receive(:puts).with(expected_result).once
227-
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once
228-
229-
AnnotateRoutes.do_annotations(wrapper_open: 'START', wrapper_close: 'END')
209+
context 'When the options "wrapper_open" and "wrapper_close" are passed' do
210+
let :expected_result do
211+
<<~EOS
212+
#{magic_comment}
213+
214+
# START
215+
# == Route Map
216+
#
217+
# Prefix Verb URI Pattern Controller#Action
218+
# myaction1 GET /url1(.:format) mycontroller1#action
219+
# myaction2 POST /url2(.:format) mycontroller2#action
220+
# myaction3 DELETE|GET /url3(.:format) mycontroller3#action
221+
# END
222+
EOS
223+
end
224+
225+
it 'annotates and wraps annotation with specified words' do
226+
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once
227+
expect(mock_file).to receive(:puts).with(expected_result).once
228+
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once
229+
230+
AnnotateRoutes.do_annotations(wrapper_open: 'START', wrapper_close: 'END')
231+
end
230232
end
231233
end
232234
end

0 commit comments

Comments
 (0)