Skip to content

Commit 2cebe0c

Browse files
committed
Merge pull request #322 from justincampbell/remove-quotes-from-ask
Remove quotes from Shell#ask
2 parents 5a36d6b + 74b8a16 commit 2cebe0c

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

lib/thor/shell/basic.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def as_unicode
379379

380380
def ask_simply(statement, color, options)
381381
default = options[:default]
382-
message = [statement, ("(#{default.inspect})" if default), nil].uniq.join(" ")
382+
message = [statement, ("(#{default})" if default), nil].uniq.join(" ")
383383
say(message, color)
384384
result = stdin.gets
385385

@@ -398,9 +398,9 @@ def ask_filtered(statement, color, options)
398398
answer_set = options[:limited_to]
399399
correct_answer = nil
400400
until correct_answer
401-
answer = ask_simply("#{statement} #{answer_set.inspect}", color, options)
401+
answers = answer_set.join(", ")
402+
answer = ask_simply("#{statement} [#{answers}]", color, options)
402403
correct_answer = answer_set.include?(answer) ? answer : nil
403-
answers = answer_set.map(&:inspect).join(", ")
404404
say("Your response must be one of: [#{answers}]. Please try again.") unless correct_answer
405405
end
406406
correct_answer

spec/shell/basic_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,27 @@ def shell
3131

3232

3333
it "prints a message to the user with the available options and determines the correctness of the answer" do
34-
$stdout.should_receive(:print).with('What\'s your favorite Neopolitan flavor? ["strawberry", "chocolate", "vanilla"] ')
34+
$stdout.should_receive(:print).with('What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ')
3535
$stdin.should_receive(:gets).and_return('chocolate')
3636
expect(shell.ask("What's your favorite Neopolitan flavor?", :limited_to => ["strawberry", "chocolate", "vanilla"])).to eq("chocolate")
3737
end
3838

3939
it "prints a message to the user with the available options and reasks the question after an incorrect repsonse" do
40-
$stdout.should_receive(:print).with('What\'s your favorite Neopolitan flavor? ["strawberry", "chocolate", "vanilla"] ').twice
41-
$stdout.should_receive(:puts).with('Your response must be one of: ["strawberry", "chocolate", "vanilla"]. Please try again.')
40+
$stdout.should_receive(:print).with('What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ').twice
41+
$stdout.should_receive(:puts).with('Your response must be one of: [strawberry, chocolate, vanilla]. Please try again.')
4242
$stdin.should_receive(:gets).and_return('moose tracks', 'chocolate')
4343
expect(shell.ask("What's your favorite Neopolitan flavor?", :limited_to => ["strawberry", "chocolate", "vanilla"])).to eq("chocolate")
4444
end
4545

4646
it "prints a message to the user containing a default and sets the default if only enter is pressed" do
47-
$stdout.should_receive(:print).with('What\'s your favorite Neopolitan flavor? ("vanilla") ')
47+
$stdout.should_receive(:print).with('What\'s your favorite Neopolitan flavor? (vanilla) ')
4848
$stdin.should_receive(:gets).and_return('')
4949
expect(shell.ask("What's your favorite Neopolitan flavor?", :default => "vanilla")).to eq("vanilla")
5050
end
5151

5252
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
53-
$stdout.should_receive(:print).with('What\'s your favorite Neopolitan flavor? ["strawberry", "chocolate", "vanilla"] ("vanilla") ').twice
54-
$stdout.should_receive(:puts).with('Your response must be one of: ["strawberry", "chocolate", "vanilla"]. Please try again.')
53+
$stdout.should_receive(:print).with('What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] (vanilla) ').twice
54+
$stdout.should_receive(:puts).with('Your response must be one of: [strawberry, chocolate, vanilla]. Please try again.')
5555
$stdin.should_receive(:gets).and_return('moose tracks', '')
5656
expect(shell.ask("What's your favorite Neopolitan flavor?", :default => "vanilla", :limited_to => ["strawberry", "chocolate", "vanilla"])).to eq("vanilla")
5757
end

0 commit comments

Comments
 (0)