diff options
author | Abinoam P. Marques Jr <abinoam@gmail.com> | 2017-11-04 18:45:07 -0300 |
---|---|---|
committer | Abinoam P. Marques Jr <abinoam@gmail.com> | 2017-11-05 11:26:00 -0300 |
commit | 0a593feeca4288129c763eee1efa251b9fdf7278 (patch) | |
tree | 522925f3efcf085963f71865fc1011349227f59c | |
parent | 979eb4d296dc0121356a9d08f211f35dbfbb8a96 (diff) | |
download | highline-0a593feeca4288129c763eee1efa251b9fdf7278.tar.gz |
Add a failing test for issue #219 dynamic
-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 |