Added src directory

This commit is contained in:
Jim Weirich
2009-12-21 15:03:20 -05:00
parent f3af22b96f
commit 47c6c6f8da
38 changed files with 2745 additions and 0 deletions

38
src/about_nil.rb Normal file
View File

@@ -0,0 +1,38 @@
require 'edgecase'
class AboutNil < EdgeCase::Koan
def test_nil_is_an_object
assert_equal __(true), nil.is_a?(Object), "Unlike NULL in other languages"
end
def test_you_dont_get_null_pointer_errors_when_calling_methods_on_nil
# What happens when you call a method that doesn't exist. The
# following begin/rescue/end code block captures the exception and
# make some assertions about it.
begin
nil.some_method_nil_doesnt_know_about
rescue Exception => ex
# What exception has been caught?
assert_equal __(NoMethodError), ex.class
# What message was attached to the exception?
# (HINT: replace __ with part of the error message.)
assert_match(/#{__("undefined method")}/, ex.message)
end
end
def test_nil_has_a_few_methods_defined_on_it
assert_equal __(true), nil.nil?
assert_equal __(""), nil.to_s
assert_equal __("nil"), nil.inspect
# THINK ABOUT IT:
#
# Is it better to use
# obj.nil?
# or
# obj == nil
# Why?
end
end