1 require File.expand_path(File.dirname(__FILE__) + '/edgecase')
3 def my_global_method(a,b)
7 class AboutMethods < EdgeCase::Koan
9 def test_calling_global_methods
10 assert_equal __, my_global_method(2,3)
13 def test_calling_global_methods_without_parentheses
14 result = my_global_method 2, 3
15 assert_equal __, result
18 # (NOTE: We are Using eval below because the example code is
19 # considered to be syntactically invalid).
20 def test_sometimes_missing_parentheses_are_ambiguous
21 eval "assert_equal 5, my_global_method 2, 3" # ENABLE CHECK
23 # Ruby doesn't know if you mean:
25 # assert_equal(5, my_global_method(2), 3)
27 # assert_equal(5, my_global_method(2, 3))
29 # Rewrite the eval string to continue.
33 # NOTE: wrong number of argument is not a SYNTAX error, but a
35 def test_calling_global_methods_with_wrong_number_of_arguments
36 exception = assert_raise(___) do
39 assert_match(/__/, exception.message)
41 exception = assert_raise(___) do
42 my_global_method(1,2,3)
44 assert_match(/__/, exception.message)
47 # ------------------------------------------------------------------
49 def method_with_defaults(a, b=:default_value)
53 def test_calling_with_default_values
54 assert_equal [1, __], method_with_defaults(1)
55 assert_equal [1, __], method_with_defaults(1, 2)
58 # ------------------------------------------------------------------
60 def method_with_var_args(*args)
64 def test_calling_with_variable_arguments
65 assert_equal __, method_with_var_args
66 assert_equal __, method_with_var_args(:one)
67 assert_equal __, method_with_var_args(:one, :two)
70 # ------------------------------------------------------------------
72 def method_with_explicit_return
75 :another_non_return_value
78 def test_method_with_explicit_return
79 assert_equal __, method_with_explicit_return
82 # ------------------------------------------------------------------
84 def method_without_explicit_return
89 def test_method_without_explicit_return
90 assert_equal __, method_without_explicit_return
93 # ------------------------------------------------------------------
95 def my_method_in_the_same_class(a, b)
99 def test_calling_methods_in_same_class
100 assert_equal __, my_method_in_the_same_class(3,4)
103 def test_calling_methods_in_same_class_with_explicit_receiver
104 assert_equal __, self.my_method_in_the_same_class(3,4)
107 # ------------------------------------------------------------------
109 def my_private_method
112 private :my_private_method
114 def test_calling_private_methods_without_receiver
115 assert_equal __, my_private_method
118 def test_calling_private_methods_with_an_explicit_receiver
119 exception = assert_raise(___) do
120 self.my_private_method
122 assert_match /__/, exception.message
125 # ------------------------------------------------------------------
139 def test_calling_methods_in_other_objects_require_explicit_receiver
141 assert_equal __, rover.name
144 def test_calling_private_methods_in_other_objects