@@ -916,25 +916,40 @@ def exit_message(prompt, choices)
916
916
let ( :spacebar ) { " " }
917
917
let ( :enter ) { "\r " }
918
918
before do
919
- prompt . on ( :keypress ) { |e | prompt . trigger ( :keydown ) if e . value == keydown }
919
+ prompt . on ( :keypress ) do |e |
920
+ prompt . trigger ( :keydown ) if e . value == keydown
921
+ end
920
922
end
921
- it "requires a min number of choices" do
922
- prompt . input << spacebar << enter << keydown << spacebar << enter
923
- prompt . input . rewind
924
-
925
- value = prompt . multi_select ( "What letter?" , choices , min : 2 , max : 2 , per_page : choices . count )
926
- expect ( value ) . to eq ( %w[ A B ] )
927
-
928
- expected_output =
929
- output_helper ( "What letter?" , choices , "A" , [ ] , init : true , min : 2 , max : 2 ,
930
- hint : "Press #{ up_down } arrow to move, Space to select and Enter to finish" ) +
931
- output_helper ( "What letter?" , choices , "A" , %w[ A ] , min : 2 , max : 2 ) +
932
- output_helper ( "What letter?" , choices , "A" , %w[ A ] , min : 2 , max : 2 ) +
933
- output_helper ( "What letter?" , choices , "B" , %w[ A ] , min : 2 , max : 2 ) +
934
- output_helper ( "What letter?" , choices , "B" , %w[ A B ] , min : 2 , max : 2 ) +
935
- exit_message ( "What letter?" , %w[ A B ] )
936
-
937
- expect ( prompt . output . string ) . to eq ( expected_output )
923
+ context "with min <= max" do
924
+ let ( :min ) { 2 }
925
+ let ( :max ) { 2 }
926
+ it "requires a min number of choices" do
927
+ prompt . input << spacebar << enter << keydown << spacebar << enter
928
+ prompt . input . rewind
929
+
930
+ value = prompt . multi_select ( "What letter?" , choices , min : min , max : max , per_page : choices . count )
931
+ expect ( value ) . to eq ( %w[ A B ] )
932
+
933
+ expected_output =
934
+ output_helper ( "What letter?" , choices , "A" , [ ] , init : true , min : min , max : max ,
935
+ hint : "Press #{ up_down } arrow to move, Space to select and Enter to finish" ) +
936
+ output_helper ( "What letter?" , choices , "A" , %w[ A ] , min : min , max : max ) +
937
+ output_helper ( "What letter?" , choices , "A" , %w[ A ] , min : min , max : max ) +
938
+ output_helper ( "What letter?" , choices , "B" , %w[ A ] , min : min , max : max ) +
939
+ output_helper ( "What letter?" , choices , "B" , %w[ A B ] , min : min , max : max ) +
940
+ exit_message ( "What letter?" , %w[ A B ] )
941
+
942
+ expect ( prompt . output . string ) . to eq ( expected_output )
943
+ end
944
+ end
945
+ context "with min > max" do
946
+ let ( :min ) { 3 }
947
+ let ( :max ) { 2 }
948
+ it "raises an error message" do
949
+ options = { min : min , max : max , per_page : choices . count }
950
+ error_msg = "min must not be greater than max"
951
+ expect { prompt . multi_select ( "What letter?" , choices , options ) } . to raise_error ( TTY ::Prompt ::ConfigurationError , error_msg )
952
+ end
938
953
end
939
954
end
940
955
end
0 commit comments