diff options
author | Abinoam P. Marques Jr <abinoam@gmail.com> | 2017-11-04 18:40:32 -0300 |
---|---|---|
committer | Abinoam P. Marques Jr <abinoam@gmail.com> | 2017-11-05 11:26:00 -0300 |
commit | 979eb4d296dc0121356a9d08f211f35dbfbb8a96 (patch) | |
tree | 79086018c7d7e66aa45274a1e3a3ef453bcc0a7b | |
parent | 46e6bba20ab921cb5600ae60e640bf2417f64efc (diff) | |
download | highline-979eb4d296dc0121356a9d08f211f35dbfbb8a96.tar.gz |
Add test for #219 static response
-rwxr-xr-x | test/test_highline.rb | 19 |
1 files changed, 19 insertions, 0 deletions
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 |