Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #252 from flomotlik/ask-nil-check

Only strip from stdin.gets if it wasn't ended with EOF
  • Loading branch information...
commit 4aecda3362ab313ea59aa96efb6fde566bd2c52a 2 parents 54cbeb8 + a57811c
@wycats wycats authored
Showing with 8 additions and 1 deletion.
  1. +1 −1  lib/thor/shell/basic.rb
  2. +7 −0 spec/shell/basic_spec.rb
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')
Please sign in to comment.
Something went wrong with that request. Please try again.