diff options
| author | Daniel Bovensiepen <[email protected]> | 2013-06-09 03:51:44 +0800 |
|---|---|---|
| committer | Daniel Bovensiepen <[email protected]> | 2013-06-09 03:51:44 +0800 |
| commit | 83d04a539e3e765b2e82d02cfbcde4a77808eb29 (patch) | |
| tree | 603549c7cd47ac095587838ad19cff23dfd0412c /test/t/methods.rb | |
| parent | 16424a14dc3b1a70ef8ebe3923c3dbd482e77c93 (diff) | |
| download | mruby-83d04a539e3e765b2e82d02cfbcde4a77808eb29.tar.gz mruby-83d04a539e3e765b2e82d02cfbcde4a77808eb29.zip | |
Improve undef tests
Diffstat (limited to 'test/t/methods.rb')
| -rw-r--r-- | test/t/methods.rb | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/test/t/methods.rb b/test/t/methods.rb new file mode 100644 index 000000000..701ebe326 --- /dev/null +++ b/test/t/methods.rb @@ -0,0 +1,65 @@ +## +# Chapter 13 "Class and modules" ISO Test + +assert('The undef statement', '13.3.7 a) 4)') do + # check that undef is undefining method + # based on the method name + + def existing_method_a; true; end + def existing_method_b; true; end + def existing_method_c; true; end + def existing_method_d; true; end + def existing_method_e; true; end + def existing_method_f; true; end + + # check that methods are defined + + assert_true(existing_method_a, 'Method should be defined') + assert_true(existing_method_b, 'Method should be defined') + assert_true(existing_method_c, 'Method should be defined') + assert_true(existing_method_d, 'Method should be defined') + assert_true(existing_method_e, 'Method should be defined') + assert_true(existing_method_f, 'Method should be defined') + + # undefine in all possible ways and check that method + # is undefined + + undef existing_method_a + assert_raise(NoMethodError) do + existing_method_a + end + + undef :existing_method_b + assert_raise(NoMethodError) do + existing_method_b + end + + undef existing_method_c, existing_method_d + assert_raise(NoMethodError) do + existing_method_c + end + assert_raise(NoMethodError) do + existing_method_d + end + + undef :existing_method_e, :existing_method_f + assert_raise(NoMethodError) do + existing_method_e + end + assert_raise(NoMethodError) do + existing_method_f + end +end + +assert('The undef statement (method undefined)', '13.3.7 a) 5)') do + # check that undef is raising NameError if + # non-existing method should be undefined + + assert_raise(NameError) do + undef non_existing_method + end + + assert_raise(NameError) do + undef :non_existing_method + end +end |
