@@ -68,19 +68,39 @@ def shell
68
68
expect ( shell . ask ( "What's your password?" , :echo => false ) ) . to eq ( "mysecretpass" )
69
69
end
70
70
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
72
72
flavors = %w( strawberry chocolate vanilla )
73
73
expect ( Thor ::LineEditor ) . to receive ( :readline ) . with ( 'What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ' , :limited_to => flavors ) . and_return ( "chocolate" )
74
74
expect ( shell . ask ( 'What\'s your favorite Neopolitan flavor?' , :limited_to => flavors ) ) . to eq ( "chocolate" )
75
75
end
76
76
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
78
78
flavors = %w( strawberry chocolate vanilla )
79
79
expect ( $stdout) . to receive ( :print ) . with ( "Your response must be one of: [strawberry, chocolate, vanilla]. Please try again.\n " )
80
80
expect ( Thor ::LineEditor ) . to receive ( :readline ) . with ( 'What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ' , :limited_to => flavors ) . and_return ( "moose tracks" , "chocolate" )
81
81
expect ( shell . ask ( 'What\'s your favorite Neopolitan flavor?' , :limited_to => flavors ) ) . to eq ( "chocolate" )
82
82
end
83
83
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
+
84
104
it "prints a message to the user containing a default and sets the default if only enter is pressed" do
85
105
expect ( Thor ::LineEditor ) . to receive ( :readline ) . with ( 'What\'s your favorite Neopolitan flavor? (vanilla) ' , :default => "vanilla" ) . and_return ( "" )
86
106
expect ( shell . ask ( 'What\'s your favorite Neopolitan flavor?' , :default => "vanilla" ) ) . to eq ( "vanilla" )
0 commit comments