From 0a593feeca4288129c763eee1efa251b9fdf7278 Mon Sep 17 00:00:00 2001 From: "Abinoam P. Marques Jr" Date: Sat, 4 Nov 2017 18:45:07 -0300 Subject: Add a failing test for issue #219 dynamic --- test/test_highline.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test') 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 -- cgit v1.2.1