From 8139d727c548863ea8f986d6e6a2249fe5bd83f2 Mon Sep 17 00:00:00 2001 From: Steve Faulkner Date: Wed, 26 Jun 2013 12:02:00 -0500 Subject: Add DelegationError class. Rasied by delegation to a nil object --- activesupport/lib/active_support/core_ext/module/delegation.rb | 4 +++- activesupport/test/core_ext/module_test.rb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb index 6d42667e97..eabc1bf84a 100644 --- a/activesupport/lib/active_support/core_ext/module/delegation.rb +++ b/activesupport/lib/active_support/core_ext/module/delegation.rb @@ -176,7 +176,7 @@ class Module end # end EOS else - exception = %(raise "#{self}##{method_prefix}#{method} delegated to #{to}.#{method}, but #{to} is nil: \#{self.inspect}") + exception = %(raise DelegationError, "#{self}##{method_prefix}#{method} delegated to #{to}.#{method}, but #{to} is nil: \#{self.inspect}") module_eval(<<-EOS, file, line - 2) def #{method_prefix}#{method}(#{definition}) # def customer_name(*args, &block) @@ -194,3 +194,5 @@ class Module end end end + +class DelegationError < StandardError ; end \ No newline at end of file diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb index 8872611fb1..ecef7754aa 100644 --- a/activesupport/test/core_ext/module_test.rb +++ b/activesupport/test/core_ext/module_test.rb @@ -207,7 +207,7 @@ class ModuleTest < ActiveSupport::TestCase def test_delegation_without_allow_nil_and_nil_value david = Someone.new("David") - assert_raise(RuntimeError) { david.street } + assert_raise(DelegationError) { david.street } end def test_delegation_to_method_that_exists_on_nil -- cgit v1.2.3