1 require File.expand_path(File.dirname(__FILE__) + '/edgecase')
3 class AboutNil < EdgeCase::Koan
4 def test_nil_is_an_object
5 assert_equal __, nil.is_a?(Object), "Unlike NULL in other languages"
8 def test_you_dont_get_null_pointer_errors_when_calling_methods_on_nil
9 # What happens when you call a method that doesn't exist. The
10 # following begin/rescue/end code block captures the exception and
11 # makes some assertions about it.
13 nil.some_method_nil_doesnt_know_about
14 rescue Exception => ex
15 # What exception has been caught?
16 assert_equal __, ex.class
18 # What message was attached to the exception?
19 # (HINT: replace __ with part of the error message.)
20 assert_match(/__/, ex.message)
24 def test_nil_has_a_few_methods_defined_on_it
25 assert_equal __, nil.nil?
26 assert_equal __, nil.to_s
27 assert_equal __, nil.inspect