mirror of
https://github.com/edgecase/ruby_koans.git
synced 2026-04-21 01:03:20 -04:00
Merged src directory with existing koans.
This commit is contained in:
@@ -2,34 +2,23 @@ require 'edgecase'
|
||||
|
||||
class AboutNil < EdgeCase::Koan
|
||||
def test_nil_is_an_object
|
||||
#
|
||||
# Hint: '!'s negate the response from what follows.
|
||||
#
|
||||
assert !nil.is_a?(Object), "Unlike NULL in other languages"
|
||||
assert_equal __, nil.is_a?(Object), "Unlike NULL in other languages"
|
||||
end
|
||||
|
||||
def test_you_dont_get_null_pointer_errors_when_calling_methods_on_nil
|
||||
#
|
||||
# What is the Exception that is thrown when you call a method that
|
||||
# does not exist?
|
||||
#
|
||||
# Hint: launch irb and try the code in the block below.
|
||||
#
|
||||
# Don't be confused by the code below yet. It's using blocks
|
||||
# which are explained later on in about_blocks.rb. For now,
|
||||
# think about it like running nil.some_method_nil_doesnt_know_about
|
||||
# in a sandbox and catching the error class into the exception
|
||||
# variable.
|
||||
#
|
||||
exception = assert_raise(___) do
|
||||
# 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 __, ex.class
|
||||
|
||||
# What message was attached to the exception?
|
||||
# (HINT: replace __ with part of the error message.)
|
||||
assert_match(/__/, ex.message)
|
||||
end
|
||||
|
||||
#
|
||||
# What is the error message itself? What substring or pattern could
|
||||
# you test against in order to have a good idea what the string is?
|
||||
#
|
||||
assert_match /__/, exception.message
|
||||
end
|
||||
|
||||
def test_nil_has_a_few_methods_defined_on_it
|
||||
|
||||
Reference in New Issue
Block a user