Skip to content

Commit

Permalink
Remove quotes from Shell#ask
Browse files Browse the repository at this point in the history
  • Loading branch information
justincampbell committed Apr 3, 2013
1 parent 5a36d6b commit 74b8a16
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions lib/thor/shell/basic.rb
Expand Up @@ -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

Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions spec/shell/basic_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 74b8a16

Please sign in to comment.