Skip to content

Commit

Permalink
Merge pull request #252 from flomotlik/ask-nil-check
Browse files Browse the repository at this point in the history
Only strip from stdin.gets if it wasn't ended with EOF
  • Loading branch information
wycats committed Sep 10, 2012
2 parents 54cbeb8 + a57811c commit 4aecda3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/thor/shell/basic.rb
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions spec/shell/basic_spec.rb
Expand Up @@ -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')
Expand Down

0 comments on commit 4aecda3

Please sign in to comment.