summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbinoam P. Marques Jr <abinoam@gmail.com>2017-11-04 18:40:32 -0300
committerAbinoam P. Marques Jr <abinoam@gmail.com>2017-11-05 11:26:00 -0300
commit979eb4d296dc0121356a9d08f211f35dbfbb8a96 (patch)
tree79086018c7d7e66aa45274a1e3a3ef453bcc0a7b
parent46e6bba20ab921cb5600ae60e640bf2417f64efc (diff)
downloadhighline-979eb4d296dc0121356a9d08f211f35dbfbb8a96.tar.gz
Add test for #219 static response
-rwxr-xr-xtest/test_highline.rb19
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