From 979eb4d296dc0121356a9d08f211f35dbfbb8a96 Mon Sep 17 00:00:00 2001 From: "Abinoam P. Marques Jr" Date: Sat, 4 Nov 2017 18:40:32 -0300 Subject: Add test for #219 static response --- test/test_highline.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/test_highline.rb b/test/test_highline.rb index 6f4d1e0..4ed1988 100755 --- a/test/test_highline.rb +++ b/test/test_highline.rb @@ -1577,6 +1577,25 @@ class TestHighLine < Minitest::Test assert_equal("Gray, James Edward", answer) end + def test_validation_with_overriding_static_message + @input << "Not valid answer\n" \ + "42\n" + + @input.rewind + + answer = @terminal.ask("Enter only numbers: ") do |question| + question.validate = ->(ans) { ans =~ /\d+/ } + question.responses[:not_valid] = "We accept only numbers over here!" + end + + assert_equal("42", answer) + assert_equal( + "Enter only numbers: We accept only numbers over here!\n" \ + "? ", + @output.string + ) + end + def test_whitespace @input << " A lot\tof \t space\t \there! \n" @input.rewind -- cgit v1.2.1