|
234 | 234 | end
|
235 | 235 | end
|
236 | 236 | end
|
237 |
| - end |
238 |
| - end |
239 | 237 |
|
240 |
| - describe 'When the result of `rake routes` is blank' do |
241 |
| - before(:each) do |
242 |
| - expect(File).to receive(:exist?).with(ROUTE_FILE).and_return(true).once |
243 |
| - expect(File).to receive(:read).with(ROUTE_FILE).and_return(route_file_content).once |
| 238 | + context 'When the result of `rake routes` is blank' do |
| 239 | + let :rake_routes_result do |
| 240 | + '' |
| 241 | + end |
244 | 242 |
|
245 |
| - expect(AnnotateRoutes).to receive(:`).with('rake routes').and_return(rake_routes_result).once |
246 |
| - end |
| 243 | + context 'When the file does not contain magic comment' do |
| 244 | + context 'When the file does not contain annotation yet' do |
| 245 | + let :route_file_content do |
| 246 | + '' |
| 247 | + end |
247 | 248 |
|
248 |
| - let :rake_routes_result do |
249 |
| - '' |
250 |
| - end |
| 249 | + context 'When no option is specified' do |
| 250 | + let :expected_result do |
| 251 | + <<~EOS |
251 | 252 |
|
252 |
| - context 'When the file does not contain magic comment' do |
253 |
| - context 'When the file does not contain annotation yet' do |
254 |
| - let :expected_result do |
255 |
| - <<~EOS |
| 253 | + # == Route Map |
| 254 | + # |
| 255 | + EOS |
| 256 | + end |
256 | 257 |
|
257 |
| - # == Route Map |
258 |
| - # |
259 |
| - EOS |
260 |
| - end |
| 258 | + it 'inserts annotations' do |
| 259 | + expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once |
| 260 | + expect(mock_file).to receive(:puts).with(expected_result).once |
| 261 | + expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once |
261 | 262 |
|
262 |
| - let :route_file_content do |
263 |
| - '' |
264 |
| - end |
| 263 | + AnnotateRoutes.do_annotations |
| 264 | + end |
| 265 | + end |
265 | 266 |
|
266 |
| - context 'When no option is specified' do |
267 |
| - it 'inserts annotations' do |
268 |
| - expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once |
269 |
| - expect(mock_file).to receive(:puts).with(expected_result).once |
270 |
| - expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once |
| 267 | + context 'When the option "ignore_routes" is specified' do |
| 268 | + let :expected_result do |
| 269 | + <<~EOS |
271 | 270 |
|
272 |
| - AnnotateRoutes.do_annotations |
273 |
| - end |
274 |
| - end |
| 271 | + # == Route Map |
| 272 | + # |
| 273 | + EOS |
| 274 | + end |
275 | 275 |
|
276 |
| - context 'When the option "ignore_routes" is specified' do |
277 |
| - it 'inserts annotations' do |
278 |
| - expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once |
279 |
| - expect(mock_file).to receive(:puts).with(expected_result).once |
280 |
| - expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once |
| 276 | + it 'inserts annotations' do |
| 277 | + expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once |
| 278 | + expect(mock_file).to receive(:puts).with(expected_result).once |
| 279 | + expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once |
281 | 280 |
|
282 |
| - AnnotateRoutes.do_annotations(ignore_routes: 'my_route') |
283 |
| - end |
284 |
| - end |
| 281 | + AnnotateRoutes.do_annotations(ignore_routes: 'my_route') |
| 282 | + end |
| 283 | + end |
285 | 284 |
|
286 |
| - context 'When the option "position_in_routes" is specified as "top"' do |
287 |
| - let :expected_result do |
288 |
| - <<~EOS |
289 |
| - # == Route Map |
290 |
| - # |
291 |
| - EOS |
292 |
| - end |
| 285 | + context 'When the option "position_in_routes" is specified as "top"' do |
| 286 | + let :expected_result do |
| 287 | + <<~EOS |
| 288 | + # == Route Map |
| 289 | + # |
| 290 | + EOS |
| 291 | + end |
293 | 292 |
|
294 |
| - it 'inserts annotations' do |
295 |
| - expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once |
296 |
| - expect(mock_file).to receive(:puts).with(expected_result).once |
297 |
| - expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once |
| 293 | + it 'inserts annotations' do |
| 294 | + expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once |
| 295 | + expect(mock_file).to receive(:puts).with(expected_result).once |
| 296 | + expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once |
298 | 297 |
|
299 |
| - AnnotateRoutes.do_annotations(position_in_routes: 'top') |
| 298 | + AnnotateRoutes.do_annotations(position_in_routes: 'top') |
| 299 | + end |
| 300 | + end |
300 | 301 | end
|
301 |
| - end |
302 |
| - end |
303 | 302 |
|
304 |
| - context 'When the file already contains annotation' do |
305 |
| - let :route_file_content do |
306 |
| - <<~EOS |
| 303 | + context 'When the file already contains annotation' do |
| 304 | + context 'When no option is specified' do |
| 305 | + let :route_file_content do |
| 306 | + <<~EOS |
307 | 307 |
|
308 |
| - # == Route Map |
309 |
| - # |
310 |
| - EOS |
311 |
| - end |
| 308 | + # == Route Map |
| 309 | + # |
| 310 | + EOS |
| 311 | + end |
312 | 312 |
|
313 |
| - it 'should skip annotations if file does already contain annotation' do |
314 |
| - expect(File).not_to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file) |
315 |
| - expect(mock_file).not_to receive(:puts) |
316 |
| - expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_UNCHANGED).once |
| 313 | + it 'should skip annotations if file does already contain annotation' do |
| 314 | + expect(File).not_to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file) |
| 315 | + expect(mock_file).not_to receive(:puts) |
| 316 | + expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_UNCHANGED).once |
317 | 317 |
|
318 |
| - AnnotateRoutes.do_annotations |
| 318 | + AnnotateRoutes.do_annotations |
| 319 | + end |
| 320 | + end |
| 321 | + end |
319 | 322 | end
|
320 |
| - end |
321 |
| - end |
322 | 323 |
|
323 |
| - context 'When the file contains magic comments' do |
324 |
| - MAGIC_COMMENTS.each do |magic_comment| |
325 |
| - describe "magic comment: #{magic_comment.inspect}" do |
326 |
| - let :route_file_content do |
327 |
| - <<~EOS |
328 |
| - #{magic_comment} |
329 |
| - Something |
330 |
| - EOS |
331 |
| - end |
| 324 | + context 'When the file contains magic comments' do |
| 325 | + MAGIC_COMMENTS.each do |magic_comment| |
| 326 | + describe "magic comment: #{magic_comment.inspect}" do |
| 327 | + let :route_file_content do |
| 328 | + <<~EOS |
| 329 | + #{magic_comment} |
| 330 | + Something |
| 331 | + EOS |
| 332 | + end |
332 | 333 |
|
333 |
| - context 'When the option "position_in_routes" is specified as "top"' do |
334 |
| - let :expected_result do |
335 |
| - <<~EOS |
336 |
| - #{magic_comment} |
| 334 | + context 'When the file does not contain annotation yet' do |
| 335 | + context 'When the option "position_in_routes" is specified as "top"' do |
| 336 | + let :expected_result do |
| 337 | + <<~EOS |
| 338 | + #{magic_comment} |
337 | 339 |
|
338 |
| - # == Route Map |
339 |
| - # |
| 340 | + # == Route Map |
| 341 | + # |
340 | 342 |
|
341 |
| - Something |
342 |
| - EOS |
343 |
| - end |
| 343 | + Something |
| 344 | + EOS |
| 345 | + end |
344 | 346 |
|
345 |
| - it 'leaves magic comment on top and adds an empty line between magic comment and annotation' do |
346 |
| - expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once |
347 |
| - expect(mock_file).to receive(:puts).with(expected_result).once |
348 |
| - expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once |
| 347 | + it 'leaves magic comment on top and adds an empty line between magic comment and annotation' do |
| 348 | + expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once |
| 349 | + expect(mock_file).to receive(:puts).with(expected_result).once |
| 350 | + expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once |
349 | 351 |
|
350 |
| - AnnotateRoutes.do_annotations(position_in_routes: 'top') |
351 |
| - end |
352 |
| - end |
| 352 | + AnnotateRoutes.do_annotations(position_in_routes: 'top') |
| 353 | + end |
| 354 | + end |
353 | 355 |
|
354 |
| - context 'When the option "position_in_routes" is specified as "bottom"' do |
355 |
| - let :expected_result do |
356 |
| - <<~EOS |
357 |
| - #{magic_comment} |
358 |
| - Something |
| 356 | + context 'When the option "position_in_routes" is specified as "bottom"' do |
| 357 | + let :expected_result do |
| 358 | + <<~EOS |
| 359 | + #{magic_comment} |
| 360 | + Something |
359 | 361 |
|
360 |
| - # == Route Map |
361 |
| - # |
362 |
| - EOS |
363 |
| - end |
| 362 | + # == Route Map |
| 363 | + # |
| 364 | + EOS |
| 365 | + end |
364 | 366 |
|
365 |
| - it 'leaves magic comment on top and adds an empty line between magic comment and annotation' do |
366 |
| - expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once |
367 |
| - expect(mock_file).to receive(:puts).with(expected_result).once |
368 |
| - expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once |
| 367 | + it 'leaves magic comment on top and adds an empty line between magic comment and annotation' do |
| 368 | + expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once |
| 369 | + expect(mock_file).to receive(:puts).with(expected_result).once |
| 370 | + expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED).once |
369 | 371 |
|
370 |
| - AnnotateRoutes.do_annotations(position_in_routes: 'bottom') |
371 |
| - end |
372 |
| - end |
| 372 | + AnnotateRoutes.do_annotations(position_in_routes: 'bottom') |
| 373 | + end |
| 374 | + end |
| 375 | + end |
373 | 376 |
|
374 |
| - context 'When the file already contains annotation' do |
375 |
| - let :route_file_content do |
376 |
| - <<~EOS |
377 |
| - #{magic_comment} |
| 377 | + context 'When the file already contains annotation' do |
| 378 | + let :route_file_content do |
| 379 | + <<~EOS |
| 380 | + #{magic_comment} |
378 | 381 |
|
379 |
| - # == Route Map |
380 |
| - # |
381 |
| - EOS |
382 |
| - end |
| 382 | + # == Route Map |
| 383 | + # |
| 384 | + EOS |
| 385 | + end |
383 | 386 |
|
384 |
| - it 'skips annotations' do |
385 |
| - expect(File).not_to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file) |
386 |
| - expect(mock_file).not_to receive(:puts) |
387 |
| - expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_UNCHANGED).once |
| 387 | + it 'skips annotations' do |
| 388 | + expect(File).not_to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file) |
| 389 | + expect(mock_file).not_to receive(:puts) |
| 390 | + expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_UNCHANGED).once |
388 | 391 |
|
389 |
| - AnnotateRoutes.do_annotations |
| 392 | + AnnotateRoutes.do_annotations |
| 393 | + end |
| 394 | + end |
390 | 395 | end
|
391 | 396 | end
|
392 | 397 | end
|
|
0 commit comments