|
319 | 319 | end
|
320 | 320 | end
|
321 | 321 |
|
322 |
| - describe 'When removing' do |
323 |
| - before(:each) do |
324 |
| - expect(File).to receive(:exist?).with(ROUTE_FILE).and_return(true) |
325 |
| - expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file) |
326 |
| - expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_REMOVED) |
| 322 | + describe '.remove_annotations' do |
| 323 | + before :each do |
| 324 | + expect(File).to receive(:exist?).with(ROUTE_FILE).and_return(true).once |
| 325 | + expect(File).to receive(:read).with(ROUTE_FILE).and_return(route_file_content).once |
| 326 | + expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file).once |
327 | 327 | end
|
328 | 328 |
|
329 |
| - it 'should remove trailing annotation and trim trailing newlines, but leave leading newlines alone' do |
330 |
| - route_file_content = <<~EOS |
| 329 | + context 'When trailing annotation exists' do |
| 330 | + let :route_file_content do |
| 331 | + <<~EOS |
331 | 332 |
|
332 | 333 |
|
333 | 334 |
|
334 |
| - ActionController::Routing... |
335 |
| - foo |
| 335 | + ActionController::Routing... |
| 336 | + foo |
336 | 337 |
|
337 | 338 |
|
338 |
| - # == Route Map |
339 |
| - # |
340 |
| - # another good line |
341 |
| - # good line |
342 |
| - EOS |
| 339 | + # == Route Map |
| 340 | + # |
| 341 | + # another good line |
| 342 | + # good line |
| 343 | + EOS |
| 344 | + end |
343 | 345 |
|
344 |
| - expected_result = <<~EOS |
| 346 | + let :expected_result do |
| 347 | + <<~EOS |
345 | 348 |
|
346 | 349 |
|
347 | 350 |
|
348 |
| - ActionController::Routing... |
349 |
| - foo |
350 |
| - EOS |
| 351 | + ActionController::Routing... |
| 352 | + foo |
| 353 | + EOS |
| 354 | + end |
| 355 | + |
| 356 | + it 'removes trailing annotation and trim trailing newlines, but leave leading newlines alone' do |
| 357 | + expect(mock_file).to receive(:puts).with(expected_result).once |
| 358 | + expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_REMOVED).once |
351 | 359 |
|
352 |
| - expect(File).to receive(:read).with(ROUTE_FILE).and_return(route_file_content) |
353 |
| - expect(mock_file).to receive(:puts).with(expected_result) |
354 |
| - AnnotateRoutes.remove_annotations |
| 360 | + AnnotateRoutes.remove_annotations |
| 361 | + end |
355 | 362 | end
|
356 | 363 |
|
357 |
| - it 'should remove prepended annotation and trim leading newlines, but leave trailing newlines alone' do |
358 |
| - route_file_content = <<~EOS |
359 |
| - # == Route Map |
360 |
| - # |
361 |
| - # another good line |
362 |
| - # good line |
| 364 | + context 'When prepended annotation exists' do |
| 365 | + let :route_file_content do |
| 366 | + <<~EOS |
| 367 | + # == Route Map |
| 368 | + # |
| 369 | + # another good line |
| 370 | + # good line |
363 | 371 |
|
364 | 372 |
|
365 | 373 |
|
366 | 374 |
|
367 |
| - Rails.application.routes.draw do |
368 |
| - root 'root#index' |
369 |
| - end |
| 375 | + Rails.application.routes.draw do |
| 376 | + root 'root#index' |
| 377 | + end |
370 | 378 |
|
371 | 379 |
|
372 | 380 |
|
373 |
| - EOS |
| 381 | + EOS |
| 382 | + end |
374 | 383 |
|
375 |
| - expected_result = <<~EOS |
376 |
| - Rails.application.routes.draw do |
377 |
| - root 'root#index' |
378 |
| - end |
| 384 | + let :expected_result do |
| 385 | + <<~EOS |
| 386 | + Rails.application.routes.draw do |
| 387 | + root 'root#index' |
| 388 | + end |
379 | 389 |
|
380 | 390 |
|
381 | 391 |
|
382 |
| - EOS |
| 392 | + EOS |
| 393 | + end |
383 | 394 |
|
384 |
| - expect(File).to receive(:read).with(ROUTE_FILE).and_return(route_file_content) |
385 |
| - expect(mock_file).to receive(:puts).with(expected_result) |
386 |
| - AnnotateRoutes.remove_annotations |
| 395 | + it 'removes prepended annotation and trim leading newlines, but leave trailing newlines alone' do |
| 396 | + expect(mock_file).to receive(:puts).with(expected_result).once |
| 397 | + expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_REMOVED).once |
| 398 | + |
| 399 | + AnnotateRoutes.remove_annotations |
| 400 | + end |
387 | 401 | end
|
388 | 402 |
|
389 |
| - it 'should not remove custom comments above route map' do |
390 |
| - route_file_content = <<~EOS |
391 |
| - # My comment |
392 |
| - # == Route Map |
393 |
| - # |
394 |
| - # another good line |
395 |
| - # good line |
396 |
| - Rails.application.routes.draw do |
397 |
| - root 'root#index' |
398 |
| - end |
399 |
| - EOS |
| 403 | + context 'When custom comments are above route map' do |
| 404 | + let :route_file_content do |
| 405 | + <<~EOS |
| 406 | + # My comment |
| 407 | + # == Route Map |
| 408 | + # |
| 409 | + # another good line |
| 410 | + # good line |
| 411 | + Rails.application.routes.draw do |
| 412 | + root 'root#index' |
| 413 | + end |
| 414 | + EOS |
| 415 | + end |
400 | 416 |
|
401 |
| - expected_result = <<~EOS |
402 |
| - # My comment |
403 |
| - Rails.application.routes.draw do |
404 |
| - root 'root#index' |
405 |
| - end |
406 |
| - EOS |
| 417 | + let :expected_result do |
| 418 | + <<~EOS |
| 419 | + # My comment |
| 420 | + Rails.application.routes.draw do |
| 421 | + root 'root#index' |
| 422 | + end |
| 423 | + EOS |
| 424 | + end |
407 | 425 |
|
408 |
| - expect(File).to receive(:read).with(ROUTE_FILE).and_return(route_file_content) |
409 |
| - expect(mock_file).to receive(:puts).with(expected_result) |
| 426 | + it 'does not remove custom comments above route map' do |
| 427 | + expect(mock_file).to receive(:puts).with(expected_result).once |
| 428 | + expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_REMOVED).once |
410 | 429 |
|
411 |
| - AnnotateRoutes.remove_annotations |
| 430 | + AnnotateRoutes.remove_annotations |
| 431 | + end |
412 | 432 | end
|
413 | 433 | end
|
414 | 434 | end
|
0 commit comments