summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbinoam Praxedes Marques Jr <abinoam@gmail.com>2016-02-19 06:09:18 -0300
committerAbinoam Praxedes Marques Jr <abinoam@gmail.com>2016-02-19 06:09:18 -0300
commitfed5fac748a97ef3f9299419126c8a71c1707fdc (patch)
treeed38a17a0fbb974a357795ee337a50fa608d0c88
parent2deec4c0df50b1c0ac502713cca6d6cf22d2b551 (diff)
downloadhighline-improve_agree_tests.tar.gz
Improve #agree tests - related to PR #189 by @kevinoidimprove_agree_tests
-rwxr-xr-xtest/test_highline.rb56
1 files changed, 48 insertions, 8 deletions
diff --git a/test/test_highline.rb b/test/test_highline.rb
index 7c95557..a75c143 100755
--- a/test/test_highline.rb
+++ b/test/test_highline.rb
@@ -34,15 +34,55 @@ class TestHighLine < Minitest::Test
@terminal = HighLine.new(@input, @output)
end
- def test_agree
- @input << "y\nyes\nYES\nyuk\nHell no!\nNo\n"
- @input.rewind
+ def test_agree_valid_yes_answers
+ valid_yes_answers = %w{ y yes Y YES }
- assert_equal(true, @terminal.agree("Yes or no? "))
- assert_equal(true, @terminal.agree("Yes or no? "))
- assert_equal(true, @terminal.agree("Yes or no? "))
- assert_equal(false, @terminal.agree("Yes or no? "))
-
+ valid_yes_answers.each do |user_input|
+ @input << "#{user_input}\n"
+ @input.rewind
+
+ assert_equal true, @terminal.agree("Yes or no? ")
+ assert_equal "Yes or no? ", @output.string
+
+ @input.truncate(@input.rewind)
+ @output.truncate(@output.rewind)
+ end
+ end
+
+ def test_agree_valid_no_answers
+ valid_no_answers = %w{ n no N NO }
+
+ valid_no_answers.each do |user_input|
+ @input << "#{user_input}\n"
+ @input.rewind
+
+ assert_equal false, @terminal.agree("Yes or no? ")
+ assert_equal "Yes or no? ", @output.string
+
+ @input.truncate(@input.rewind)
+ @output.truncate(@output.rewind)
+ end
+ end
+
+ def test_agree_invalid_answers
+ invalid_answers = [ "ye", "yuk", "nope", "Oh yes", "Oh no", "Hell no!"]
+
+ invalid_answers.each do |user_input|
+ # Each invalid answer, should be followed by a 'y' (as the question is reasked)
+ @input << "#{user_input}\ny\n"
+ @input.rewind
+
+ assert_equal true, @terminal.agree("Yes or no? ")
+
+ # It reasks the question if the answer is invalid
+ assert_equal "Yes or no? Please enter \"yes\" or \"no\".\nYes or no? ", @output.string
+
+ @input.truncate(@input.rewind)
+ @output.truncate(@output.rewind)
+ end
+ end
+
+ def test_agree_with_getc
@input.truncate(@input.rewind)
@input << "yellow"
@input.rewind