Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Merged
merged 1 commit into from

2 participants

@flomotlik

When stdin.gets is ended by pressing ctrl-d or the equivalent EOF keys
it returns nil and ask_simply raises a NoMethodException when calling
strip.

@flomotlik flomotlik Only strip from stdin.gets if it wasn't ended with EOF
When stdin.gets is ended by pressing ctrl-d or the equivalent EOF keys
it returns nil and ask_simply raises a NoMethodException when calling
strip.
a57811c
@wycats wycats merged commit 4aecda3 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 10, 2012
  1. @flomotlik

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

    flomotlik authored
    When stdin.gets is ended by pressing ctrl-d or the equivalent EOF keys
    it returns nil and ask_simply raises a NoMethodException when calling
    strip.
This page is out of date. Refresh to see the latest.
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')
Something went wrong with that request. Please try again.