Browse files

Remove quotes from Shell#ask

  • Loading branch information...
1 parent 5a36d6b commit 74b8a16966e8f3ea784eefe6c5d6c2b7a044741e @justincampbell justincampbell committed Apr 3, 2013
Showing with 9 additions and 9 deletions.
  1. +3 −3 lib/thor/shell/basic.rb
  2. +6 −6 spec/shell/basic_spec.rb
View
6 lib/thor/shell/basic.rb
@@ -379,7 +379,7 @@ def as_unicode
def ask_simply(statement, color, options)
default = options[:default]
- message = [statement, ("(#{default.inspect})" if default), nil].uniq.join(" ")
+ message = [statement, ("(#{default})" if default), nil].uniq.join(" ")
say(message, color)
result = stdin.gets
@@ -398,9 +398,9 @@ def ask_filtered(statement, color, options)
answer_set = options[:limited_to]
correct_answer = nil
until correct_answer
- answer = ask_simply("#{statement} #{answer_set.inspect}", color, options)
+ answers = answer_set.join(", ")
+ answer = ask_simply("#{statement} [#{answers}]", color, options)
correct_answer = answer_set.include?(answer) ? answer : nil
- answers = answer_set.map(&:inspect).join(", ")
say("Your response must be one of: [#{answers}]. Please try again.") unless correct_answer
end
correct_answer
View
12 spec/shell/basic_spec.rb
@@ -31,27 +31,27 @@ def shell
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"] ')
+ $stdout.should_receive(:print).with('What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ')
$stdin.should_receive(:gets).and_return('chocolate')
expect(shell.ask("What's your favorite Neopolitan flavor?", :limited_to => ["strawberry", "chocolate", "vanilla"])).to eq("chocolate")
end
it "prints a message to the user with the available options and reasks the question after an incorrect repsonse" do
- $stdout.should_receive(:print).with('What\'s your favorite Neopolitan flavor? ["strawberry", "chocolate", "vanilla"] ').twice
- $stdout.should_receive(:puts).with('Your response must be one of: ["strawberry", "chocolate", "vanilla"]. Please try again.')
+ $stdout.should_receive(:print).with('What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ').twice
+ $stdout.should_receive(:puts).with('Your response must be one of: [strawberry, chocolate, vanilla]. Please try again.')
$stdin.should_receive(:gets).and_return('moose tracks', 'chocolate')
expect(shell.ask("What's your favorite Neopolitan flavor?", :limited_to => ["strawberry", "chocolate", "vanilla"])).to eq("chocolate")
end
it "prints a message to the user containing a default and sets the default if only enter is pressed" do
- $stdout.should_receive(:print).with('What\'s your favorite Neopolitan flavor? ("vanilla") ')
+ $stdout.should_receive(:print).with('What\'s your favorite Neopolitan flavor? (vanilla) ')
$stdin.should_receive(:gets).and_return('')
expect(shell.ask("What's your favorite Neopolitan flavor?", :default => "vanilla")).to eq("vanilla")
end
it "prints a message to the user with the available options and reasks the question after an incorrect repsonse and then returns the default" do
- $stdout.should_receive(:print).with('What\'s your favorite Neopolitan flavor? ["strawberry", "chocolate", "vanilla"] ("vanilla") ').twice
- $stdout.should_receive(:puts).with('Your response must be one of: ["strawberry", "chocolate", "vanilla"]. Please try again.')
+ $stdout.should_receive(:print).with('What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] (vanilla) ').twice
+ $stdout.should_receive(:puts).with('Your response must be one of: [strawberry, chocolate, vanilla]. Please try again.')
$stdin.should_receive(:gets).and_return('moose tracks', '')
expect(shell.ask("What's your favorite Neopolitan flavor?", :default => "vanilla", :limited_to => ["strawberry", "chocolate", "vanilla"])).to eq("vanilla")
end

0 comments on commit 74b8a16

Please sign in to comment.