Skip to content

Commit 86dc2c5

Browse files
committed
Add tests for frozen option of routing annotations
Signed-off-by: kg8m <[email protected]>
1 parent a76da82 commit 86dc2c5

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

spec/lib/annotate/annotate_routes_spec.rb

+65
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,71 @@
556556
end
557557
end
558558
end
559+
560+
describe 'frozen option' do
561+
let :aborted_message do
562+
"annotate error. #{ROUTE_FILE} needs to be updated, but annotate was run with `--frozen`."
563+
end
564+
565+
let :rake_routes_result do
566+
<<-EOS
567+
Prefix Verb URI Pattern Controller#Action
568+
myaction1 GET /url1(.:format) mycontroller1#action
569+
myaction2 POST /url2(.:format) mycontroller2#action
570+
myaction3 DELETE|GET /url3(.:format) mycontroller3#action
571+
EOS
572+
end
573+
574+
before :each do
575+
expect(File).to receive(:exist?).with(ROUTE_FILE).and_return(true).once
576+
expect(File).to receive(:read).with(ROUTE_FILE).and_return(route_file_content).once
577+
578+
expect(AnnotateRoutes::HeaderGenerator).to receive(:`).with('rake routes').and_return(rake_routes_result).once
579+
end
580+
581+
context 'when annotation does not exists' do
582+
let :route_file_content do
583+
''
584+
end
585+
586+
it 'aborts' do
587+
expect { AnnotateRoutes.do_annotations(frozen: true) }.to raise_error SystemExit, aborted_message
588+
end
589+
end
590+
591+
context 'when annotation exists but is not updated' do
592+
let :route_file_content do
593+
<<~EOS
594+
# == Route Map
595+
#
596+
# Prefix Verb URI Pattern Controller#Action
597+
# myaction2 POST /url2(.:format) mycontroller2#action
598+
# myaction3 DELETE|GET /url3(.:format) mycontroller3#action
599+
EOS
600+
end
601+
602+
it 'aborts' do
603+
expect { AnnotateRoutes.do_annotations(frozen: true) }.to raise_error SystemExit, aborted_message
604+
end
605+
end
606+
607+
context 'when annotation exists and is already updated' do
608+
let :route_file_content do
609+
<<~EOS
610+
# == Route Map
611+
#
612+
# Prefix Verb URI Pattern Controller#Action
613+
# myaction1 GET /url1(.:format) mycontroller1#action
614+
# myaction2 POST /url2(.:format) mycontroller2#action
615+
# myaction3 DELETE|GET /url3(.:format) mycontroller3#action
616+
EOS
617+
end
618+
619+
it 'does NOT abort' do
620+
expect { AnnotateRoutes.do_annotations(frozen: true) }.not_to raise_error
621+
end
622+
end
623+
end
559624
end
560625

561626
describe '.remove_annotations' do

0 commit comments

Comments
 (0)