Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix the line number in the backtrace when Module#delegate raises

  • Loading branch information...
commit 63d100ea35a7fabea25c37f654177c3828fc1dcb 1 parent 7b56fb0
Jon Leighton jonleighton authored
2  activesupport/lib/active_support/core_ext/module/delegation.rb
View
@@ -133,7 +133,7 @@ def delegate(*methods)
%(raise "#{self}##{method_prefix}#{method} delegated to #{to}.#{method}, but #{to} is nil: \#{self.inspect}")
end
- module_eval(<<-EOS, file, line - 5)
+ module_eval(<<-EOS, file, line - 1)
def #{method_prefix}#{method}(*args, &block) # def customer_name(*args, &block)
#{to}.#{call}*args, &block) # client.name(*args, &block)
rescue NoMethodError # rescue NoMethodError
14 activesupport/test/core_ext/module_test.rb
View
@@ -38,9 +38,12 @@ def private_method
end
end
-Someone = Struct.new(:name, :place) do
+class Someone < Struct.new(:name, :place)
delegate :street, :city, :to_f, :protected_method, :private_method, :to => :place
delegate :upcase, :to => "place.city"
+
+ FAILED_DELEGATE_LINE = __LINE__ + 1
+ delegate :foo, :to => :place
end
Invoice = Struct.new(:client) do
@@ -182,6 +185,15 @@ class << self
end
end
+ def test_delegation_exception_backtrace
+ someone = Someone.new("foo", "bar")
+ someone.foo
+ rescue NoMethodError => e
+ file_and_line = "#{__FILE__}:#{Someone::FAILED_DELEGATE_LINE}"
+ assert e.backtrace.first.include?(file_and_line),
+ "[#{e.backtrace.first}] did not include [#{file_and_line}]"
+ end
+
def test_parent
assert_equal Yz::Zy, Yz::Zy::Cd.parent
assert_equal Yz, Yz::Zy.parent
Please sign in to comment.
Something went wrong with that request. Please try again.