Skip to content

Commit

Permalink
Methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee Smith committed Dec 27, 2010
1 parent 81a0f8c commit c27554e
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions about_methods.rb
Expand Up @@ -7,18 +7,18 @@ def my_global_method(a,b)
class AboutMethods < EdgeCase::Koan

def test_calling_global_methods
assert_equal __, my_global_method(2,3)
assert_equal 5, my_global_method(2,3)
end

def test_calling_global_methods_without_parentheses
result = my_global_method 2, 3
assert_equal __, result
assert_equal 5, result
end

# (NOTE: We are Using eval below because the example code is
# considered to be syntactically invalid).
def test_sometimes_missing_parentheses_are_ambiguous
eval "assert_equal 5, my_global_method 2, 3" # ENABLE CHECK
eval "assert_equal 5, my_global_method(2, 3)" # ENABLE CHECK
#
# Ruby doesn't know if you mean:
#
Expand All @@ -33,15 +33,15 @@ def test_sometimes_missing_parentheses_are_ambiguous
# NOTE: wrong number of argument is not a SYNTAX error, but a
# runtime error.
def test_calling_global_methods_with_wrong_number_of_arguments
exception = assert_raise(___) do
exception = assert_raise(ArgumentError) do
my_global_method
end
assert_match(/__/, exception.message)
assert_match(/wrong number of arguments/, exception.message)

exception = assert_raise(___) do
exception = assert_raise(ArgumentError) do
my_global_method(1,2,3)
end
assert_match(/__/, exception.message)
assert_match(/wrong number of arguments/, exception.message)
end

# ------------------------------------------------------------------
Expand All @@ -51,8 +51,8 @@ def method_with_defaults(a, b=:default_value)
end

def test_calling_with_default_values
assert_equal [1, __], method_with_defaults(1)
assert_equal [1, __], method_with_defaults(1, 2)
assert_equal [1, :default_value], method_with_defaults(1)
assert_equal [1, 2], method_with_defaults(1, 2)
end

# ------------------------------------------------------------------
Expand All @@ -62,9 +62,9 @@ def method_with_var_args(*args)
end

def test_calling_with_variable_arguments
assert_equal __, method_with_var_args
assert_equal __, method_with_var_args(:one)
assert_equal __, method_with_var_args(:one, :two)
assert_equal [], method_with_var_args
assert_equal [:one], method_with_var_args(:one)
assert_equal [:one, :two], method_with_var_args(:one, :two)
end

# ------------------------------------------------------------------
Expand All @@ -76,7 +76,7 @@ def method_with_explicit_return
end

def test_method_with_explicit_return
assert_equal __, method_with_explicit_return
assert_equal :return_value, method_with_explicit_return
end

# ------------------------------------------------------------------
Expand All @@ -87,7 +87,7 @@ def method_without_explicit_return
end

def test_method_without_explicit_return
assert_equal __, method_without_explicit_return
assert_equal :return_value, method_without_explicit_return
end

# ------------------------------------------------------------------
Expand All @@ -97,11 +97,11 @@ def my_same_class_method(a, b)
end

def test_calling_methods_in_same_class
assert_equal __, my_same_class_method(3,4)
assert_equal 12, my_same_class_method(3,4)
end

def test_calling_methods_in_same_class_with_explicit_receiver
assert_equal __, self.my_same_class_method(3,4)
assert_equal 12, self.my_same_class_method(3,4)
end

# ------------------------------------------------------------------
Expand All @@ -112,14 +112,14 @@ def my_private_method
private :my_private_method

def test_calling_private_methods_without_receiver
assert_equal __, my_private_method
assert_equal 'a secret', my_private_method
end

def test_calling_private_methods_with_an_explicit_receiver
exception = assert_raise(___) do
exception = assert_raise(NoMethodError) do
self.my_private_method
end
assert_match /__/, exception.message
assert_match /private method/, exception.message
end

# ------------------------------------------------------------------
Expand All @@ -138,12 +138,12 @@ def tail

def test_calling_methods_in_other_objects_require_explicit_receiver
rover = Dog.new
assert_equal __, rover.name
assert_equal 'Fido', rover.name
end

def test_calling_private_methods_in_other_objects
rover = Dog.new
assert_raise(___) do
assert_raise(NoMethodError) do
rover.tail
end
end
Expand Down

0 comments on commit c27554e

Please sign in to comment.