Skip to content

Commit 615d69c

Browse files
committed
Merge pull request #369 from sirbrillig/correct_default_on_no
Correct Basic#no? for misc. input
2 parents db744b5 + fa44776 commit 615d69c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/thor/shell/basic.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def yes?(statement, color=nil)
112112
# "no".
113113
#
114114
def no?(statement, color=nil)
115-
!yes?(statement, color)
115+
!!(ask(statement, color) =~ is?(:no))
116116
end
117117

118118
# Prints values in columns

spec/shell/basic_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ def shell
7373
expect($stdin).to receive(:gets).and_return('n')
7474
expect(shell.yes?("Should I overwrite it?")).not_to be true
7575
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
7682
end
7783

7884
describe "#no?" do
@@ -85,6 +91,12 @@ def shell
8591
expect($stdin).to receive(:gets).and_return('Yes')
8692
expect(shell.no?("Should I overwrite it?")).to be false
8793
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
88100
end
89101

90102
describe "#say" do

0 commit comments

Comments
 (0)