Only strip from stdin.gets if it wasn't ended with EOF #252

Merged
merged 1 commit into from Sep 10, 2012
View
2 lib/thor/shell/basic.rb
@@ -370,7 +370,7 @@ def as_unicode
def ask_simply(statement, color=nil)
say("#{statement} ", color)
- stdin.gets.strip
+ stdin.gets.tap{|text| text.strip! if text}
end
def ask_filtered(statement, answer_set, *args)
View
7 spec/shell/basic_spec.rb
@@ -24,6 +24,13 @@ def shell
shell.ask("Should I overwrite it?").should == "Sure"
end
+ it "prints a message and returns nil if EOF is sent to stdin" do
+ $stdout.should_receive(:print).with(" ")
+ $stdin.should_receive(:gets).and_return(nil)
+ shell.ask("").should == nil
+ end
+
+
it "prints a message to the user with the available options and determines the correctness of the answer" do
$stdout.should_receive(:print).with('What\'s your favorite Neopolitan flavor? ["strawberry", "chocolate", "vanilla"] ')
$stdin.should_receive(:gets).and_return('chocolate')