File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -112,7 +112,7 @@ def yes?(statement, color=nil)
112
112
# "no".
113
113
#
114
114
def no? ( statement , color = nil )
115
- !yes? ( statement , color )
115
+ !! ( ask ( statement , color ) =~ is? ( :no ) )
116
116
end
117
117
118
118
# Prints values in columns
Original file line number Diff line number Diff line change @@ -73,6 +73,12 @@ def shell
73
73
expect ( $stdin) . to receive ( :gets ) . and_return ( 'n' )
74
74
expect ( shell . yes? ( "Should I overwrite it?" ) ) . not_to be true
75
75
end
76
+
77
+ it "asks the user and returns false if the user replies with an answer other than yes or no" do
78
+ expect ( $stdout) . to receive ( :print ) . with ( "Should I overwrite it? " )
79
+ expect ( $stdin) . to receive ( :gets ) . and_return ( 'foobar' )
80
+ expect ( shell . yes? ( "Should I overwrite it?" ) ) . to be_false
81
+ end
76
82
end
77
83
78
84
describe "#no?" do
@@ -85,6 +91,12 @@ def shell
85
91
expect ( $stdin) . to receive ( :gets ) . and_return ( 'Yes' )
86
92
expect ( shell . no? ( "Should I overwrite it?" ) ) . to be false
87
93
end
94
+
95
+ it "asks the user and returns false if the user replies with an answer other than yes or no" do
96
+ expect ( $stdout) . to receive ( :print ) . with ( "Should I overwrite it? " )
97
+ expect ( $stdin) . to receive ( :gets ) . and_return ( 'foobar' )
98
+ expect ( shell . no? ( "Should I overwrite it?" ) ) . to be_false
99
+ end
88
100
end
89
101
90
102
describe "#say" do
You can’t perform that action at this time.
0 commit comments