From 7387767426a6382f884cdda9259e34dbc6396b14 Mon Sep 17 00:00:00 2001 From: Krzysztof Wilczynski Date: Sat, 31 Aug 2013 17:46:59 +0100 Subject: [PATCH] Add new tests concerned about testing custom exceptions classes et al ... This is to test whether custom exception classes and custom attributes they use hold water. Signed-off-by: Krzysztof Wilczynski --- test/test_fizzbuzz.rb | 47 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/test/test_fizzbuzz.rb b/test/test_fizzbuzz.rb index fb319e6..b5286ff 100644 --- a/test/test_fizzbuzz.rb +++ b/test/test_fizzbuzz.rb @@ -67,7 +67,7 @@ def test_fizzbuzz_singleton_methods end def test_fizzbuzz_new_instance - fb = FizzBuzz.new(0, 0) + fb = FizzBuzz.new(DEFAULT_START, DEFAULT_STOP) assert_equal(fb.class, FizzBuzz) end @@ -393,6 +393,51 @@ def test_for_range_error FizzBuzz.new(-@large_bignum, DEFAULT_STOP) end end + + def test_error_attributes_not_nil + fb = FizzBuzz.new(DEFAULT_START, DEFAULT_STOP) + + begin + fb.start = 1 + fb.stop = 0 + rescue FizzBuzz::RangeError => error + assert_equal(error.start, 1) + assert_equal(error.stop, 0) + end + end + + def test_error_attributes_nil + begin + FizzBuzz.new('', '') + rescue FizzBuzz::TypeError => error + assert_equal(error.start, nil) + assert_equal(error.stop, nil) + end + end + + def test_start_type_error_message + begin + FizzBuzz.new('', DEFAULT_STOP) + rescue FizzBuzz::TypeError => error + assert_equal(error.message, 'must be an Integer or Bignum type for start') + end + end + + def test_stop_type_error_message + begin + FizzBuzz.new(DEFAULT_START, '') + rescue FizzBuzz::TypeError => error + assert_equal(error.message, 'must be an Integer or Bignum type for stop') + end + end + + def test_range_error_message + begin + FizzBuzz.new(DEFAULT_STOP, DEFAULT_START) + rescue FizzBuzz::RangeError => error + assert_equal(error.message, 'start value is higher than stop value') + end + end end # vim: set ts=2 sw=2 sts=2 et :