Skip to content

Commit

Permalink
Add new tests concerned about testing custom exceptions classes et al…
Browse files Browse the repository at this point in the history
… ...

This is to test whether custom exception classes and custom attributes
they use hold water.

Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
  • Loading branch information
kwilczynski committed Aug 31, 2013
1 parent cb6bbc3 commit 7387767
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion test/test_fizzbuzz.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 :
Expand Down

0 comments on commit 7387767

Please sign in to comment.