diff options
-rwxr-xr-x | test/test_highline.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/test_highline.rb b/test/test_highline.rb index 4ed1988..67d8fad 100755 --- a/test/test_highline.rb +++ b/test/test_highline.rb @@ -1596,6 +1596,27 @@ class TestHighLine < Minitest::Test ) end + def test_validation_with_overriding_dynamic_message + @input << "Forty two\n" \ + "42\n" + + @input.rewind + + answer = @terminal.ask("Enter only numbers: ") do |question| + question.validate = ->(ans) { ans =~ /\d+/ } + question.responses[:not_valid] = + ->(ans) { "#{ans} is not a valid answer" } + end + + assert_equal("42", answer) + assert_equal( + "Enter only numbers: " \ + "Forty two is not a valid answer\n" \ + "? ", + @output.string + ) + end + def test_whitespace @input << " A lot\tof \t space\t \there! \n" @input.rewind |