@@ -68,19 +68,40 @@ 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
+ #this one
85
+ 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
86
+ flavors = %w( strawberry chocolate vanilla )
87
+ expect ( $stdout) . to receive ( :print ) . with ( "Your response must be one of: [strawberry, chocolate, vanilla]. Please try again.\n " )
88
+ expect ( Thor ::LineEditor ) . to receive ( :readline ) . with ( 'What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ' , :limited_to => flavors ) . and_return ( "cHoCoLaTe" , "chocolate" )
89
+ expect ( shell . ask ( 'What\'s your favorite Neopolitan flavor?' , :limited_to => flavors ) ) . to eq ( "chocolate" )
90
+ end
91
+
92
+ it "prints a message to the user with the available options, expects case-insensitive matching, and determines the correctness of the answer" do
93
+ flavors = %w( strawberry chocolate vanilla )
94
+ 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" )
95
+ expect ( shell . ask ( 'What\'s your favorite Neopolitan flavor?' , :limited_to => flavors , :case_insensitive => true ) ) . to eq ( "chocolate" )
96
+ end
97
+
98
+ it "prints a message to the user with the available options, expects case-insensitive matching, and reasks the question after an incorrect response" do
99
+ flavors = %w( strawberry chocolate vanilla )
100
+ expect ( $stdout) . to receive ( :print ) . with ( "Your response must be one of: [strawberry, chocolate, vanilla]. Please try again.\n " )
101
+ 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" )
102
+ expect ( shell . ask ( 'What\'s your favorite Neopolitan flavor?' , :limited_to => flavors , :case_insensitive => true ) ) . to eq ( "chocolate" )
103
+ end
104
+
84
105
it "prints a message to the user containing a default and sets the default if only enter is pressed" do
85
106
expect ( Thor ::LineEditor ) . to receive ( :readline ) . with ( 'What\'s your favorite Neopolitan flavor? (vanilla) ' , :default => "vanilla" ) . and_return ( "" )
86
107
expect ( shell . ask ( 'What\'s your favorite Neopolitan flavor?' , :default => "vanilla" ) ) . to eq ( "vanilla" )
0 commit comments