summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbinoam Praxedes Marques Jr <abinoam@gmail.com>2016-02-19 06:09:18 -0300
committerKevin Locke <kevin@kevinlocke.name>2016-02-19 06:24:59 -0800
commit5f0a9447c34f5fa56ede6aaf98859cf3664157f9 (patch)
tree669e065f7f6c4735b4c0ea1947f5c6ed115643be
parent6bba9b61465cc4f3b899c6fd2838ec39bd5c7d95 (diff)
downloadhighline-5f0a9447c34f5fa56ede6aaf98859cf3664157f9.tar.gz
Improve #agree tests - related to PR #189 by @kevinoid
-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