summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/highline/question/answer_converter.rb7
-rw-r--r--lib/highline/question_asker.rb1
-rwxr-xr-xtest/test_highline.rb19
3 files changed, 22 insertions, 5 deletions
diff --git a/lib/highline/question/answer_converter.rb b/lib/highline/question/answer_converter.rb
index 76558ae..6a4585c 100644
--- a/lib/highline/question/answer_converter.rb
+++ b/lib/highline/question/answer_converter.rb
@@ -9,7 +9,7 @@ class HighLine
extend Forwardable
def_delegators :@question,
- :answer, :answer=, :check_range,
+ :answer, :answer=,
:directory, :answer_type, :choices_complete
# It should be initialized with a Question object.
@@ -26,10 +26,7 @@ class HighLine
# it makes the conversion and returns the answer.
# @return [Object] the converted answer.
def convert
- return unless answer_type
-
- self.answer = convert_by_answer_type
- check_range
+ self.answer = convert_by_answer_type if answer_type
answer
end
diff --git a/lib/highline/question_asker.rb b/lib/highline/question_asker.rb
index 03b3ff7..d28d36c 100644
--- a/lib/highline/question_asker.rb
+++ b/lib/highline/question_asker.rb
@@ -31,6 +31,7 @@ class HighLine
raise NotValidQuestionError unless question.valid_answer?
question.convert
+ question.check_range
if question.confirm
confirmation = @highline.send(:confirm, question)
diff --git a/test/test_highline.rb b/test/test_highline.rb
index 67d8fad..e623305 100755
--- a/test/test_highline.rb
+++ b/test/test_highline.rb
@@ -1358,6 +1358,25 @@ class TestHighLine < Minitest::Test
"? ", @output.string)
end
+ def test_range_requirements_with_array_of_strings
+ @input.truncate(@input.rewind)
+ @input << "z\nx\nb\n"
+ @input.rewind
+ @output.truncate(@output.rewind)
+
+ answer = @terminal.ask("Letter a, b, or c? ") do |q|
+ q.in = %w[ a b c ]
+ end
+ assert_equal("b", answer)
+ assert_equal("Letter a, b, or c? " \
+ "Your answer isn't within the expected range " \
+ "(included in [\"a\", \"b\", \"c\"]).\n" \
+ "? " \
+ "Your answer isn't within the expected range " \
+ "(included in [\"a\", \"b\", \"c\"]).\n" \
+ "? ", @output.string)
+ end
+
def test_reask
number = 61_676
@input << "Junk!\n" << number << "\n"