Skip to content

Commit 5d18b3c

Browse files
committed
Add tests for frozen option of routing annotations
Signed-off-by: kg8m <takumi.kagiyama@gmail.com>
1 parent a76da82 commit 5d18b3c

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

spec/lib/annotate/annotate_routes_spec.rb

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

561623
describe '.remove_annotations' do

0 commit comments

Comments
 (0)