Skip to content

Commit

Permalink
Restored use of message_source.inspect for nonstrings. Fixed tests to…
Browse files Browse the repository at this point in the history
… not expect colons.
  • Loading branch information
Keith Bennett committed Jan 4, 2014
1 parent 9a935de commit ad0f7d9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions lib/highline/question.rb
Expand Up @@ -231,19 +231,23 @@ def build_responses(message_source = answer_type, new_hash_wins = false)

append_default unless default.nil?

choice_error_str = "You must choose one of the following: " +
message_source.map { |s| "#{s}" }.join(', ') + '.'
choice_error_str_func = lambda do
message_source.is_a?(Array) \
? '[' + message_source.map { |s| "#{s}" }.join(', ') + ']' \
: message_source.inspect
end

old_hash = @responses

new_hash = { :ambiguous_completion =>
"Ambiguous choice. " + choice_error_str,
"Ambiguous choice. Please choose one of " +
choice_error_str_func.call + '.',
:ask_on_error =>
"? ",
:invalid_type =>
"You must enter a valid #{message_source}.",
:no_completion =>
"You must choose one of " + choice_error_str,
"You must choose one of " + choice_error_str_func.call + '.',
:not_in_range =>
"Your answer isn't within the expected range " +
"(#{expected_range}).",
Expand Down
4 changes: 2 additions & 2 deletions test/tc_highline.rb
Expand Up @@ -168,7 +168,7 @@ def test_bug_fixes
end
assert_equal(languages.last, answer)
assert_equal( "What is your favorite programming language? " +
"You must choose one of [:Perl, :Python, :Ruby].\n" +
"You must choose one of [Perl, Python, Ruby].\n" +
"? ", @output.string )
end

Expand Down Expand Up @@ -877,7 +877,7 @@ def test_reask
assert_equal(:generate, answer)
assert_equal( "Select a mode: " +
"Ambiguous choice. " +
"Please choose one of [:generate, :gentle].\n" +
"Please choose one of [generate, gentle].\n" +
"? ", @output.string )
end

Expand Down

0 comments on commit ad0f7d9

Please sign in to comment.