diff options
author | Abinoam P. Marques Jr <abinoam@gmail.com> | 2023-01-01 11:27:13 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-01 11:27:13 -0300 |
commit | 49eed912b0113b3b9c0949f0ef056f390ed359ba (patch) | |
tree | bea23faca058f9ba76054a2c732c4819a861ebef | |
parent | 33cee8a7a7946e27b3be8459721f69c73eee7694 (diff) | |
parent | f147388e42c592cf2a6930956c6160970f519d04 (diff) | |
download | highline-49eed912b0113b3b9c0949f0ef056f390ed359ba.tar.gz |
Merge pull request #256 from abinoam/issue_249
Fix #249 - Question#in convert and check_range
-rw-r--r-- | lib/highline/question/answer_converter.rb | 7 | ||||
-rw-r--r-- | lib/highline/question_asker.rb | 1 | ||||
-rwxr-xr-x | test/test_highline.rb | 19 |
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" |