@@ -68,19 +68,39 @@ def shell
6868 expect ( shell . ask ( "What's your password?" , :echo => false ) ) . to eq ( "mysecretpass" )
6969 end
7070
71- it "prints a message to the user with the available options and determines the correctness of the answer" do
71+ it "prints a message to the user with the available options, expects case-sensitive matching, and determines the correctness of the answer" do
7272 flavors = %w( strawberry chocolate vanilla )
7373 expect ( Thor ::LineEditor ) . to receive ( :readline ) . with ( 'What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ' , :limited_to => flavors ) . and_return ( "chocolate" )
7474 expect ( shell . ask ( 'What\'s your favorite Neopolitan flavor?' , :limited_to => flavors ) ) . to eq ( "chocolate" )
7575 end
7676
77- it "prints a message to the user with the available options and reasks the question after an incorrect response" do
77+ it "prints a message to the user with the available options, expects case-sensitive matching, and reasks the question after an incorrect response" do
7878 flavors = %w( strawberry chocolate vanilla )
7979 expect ( $stdout) . to receive ( :print ) . with ( "Your response must be one of: [strawberry, chocolate, vanilla]. Please try again.\n " )
8080 expect ( Thor ::LineEditor ) . to receive ( :readline ) . with ( 'What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ' , :limited_to => flavors ) . and_return ( "moose tracks" , "chocolate" )
8181 expect ( shell . ask ( 'What\'s your favorite Neopolitan flavor?' , :limited_to => flavors ) ) . to eq ( "chocolate" )
8282 end
8383
84+ it "prints a message to the user with the available options, expects case-sensitive matching, and reasks the question after a case-insensitive match" do
85+ flavors = %w( strawberry chocolate vanilla )
86+ expect ( $stdout) . to receive ( :print ) . with ( "Your response must be one of: [strawberry, chocolate, vanilla]. Please try again.\n " )
87+ expect ( Thor ::LineEditor ) . to receive ( :readline ) . with ( 'What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ' , :limited_to => flavors ) . and_return ( "cHoCoLaTe" , "chocolate" )
88+ expect ( shell . ask ( 'What\'s your favorite Neopolitan flavor?' , :limited_to => flavors ) ) . to eq ( "chocolate" )
89+ end
90+
91+ it "prints a message to the user with the available options, expects case-insensitive matching, and determines the correctness of the answer" do
92+ flavors = %w( strawberry chocolate vanilla )
93+ expect ( Thor ::LineEditor ) . to receive ( :readline ) . with ( 'What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ' , :limited_to => flavors , :case_insensitive => true ) . and_return ( "CHOCOLATE" )
94+ expect ( shell . ask ( 'What\'s your favorite Neopolitan flavor?' , :limited_to => flavors , :case_insensitive => true ) ) . to eq ( "chocolate" )
95+ end
96+
97+ it "prints a message to the user with the available options, expects case-insensitive matching, and reasks the question after an incorrect response" do
98+ flavors = %w( strawberry chocolate vanilla )
99+ expect ( $stdout) . to receive ( :print ) . with ( "Your response must be one of: [strawberry, chocolate, vanilla]. Please try again.\n " )
100+ expect ( Thor ::LineEditor ) . to receive ( :readline ) . with ( 'What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ' , :limited_to => flavors , :case_insensitive => true ) . and_return ( "moose tracks" , "chocolate" )
101+ expect ( shell . ask ( 'What\'s your favorite Neopolitan flavor?' , :limited_to => flavors , :case_insensitive => true ) ) . to eq ( "chocolate" )
102+ end
103+
84104 it "prints a message to the user containing a default and sets the default if only enter is pressed" do
85105 expect ( Thor ::LineEditor ) . to receive ( :readline ) . with ( 'What\'s your favorite Neopolitan flavor? (vanilla) ' , :default => "vanilla" ) . and_return ( "" )
86106 expect ( shell . ask ( 'What\'s your favorite Neopolitan flavor?' , :default => "vanilla" ) ) . to eq ( "vanilla" )
0 commit comments