Project

General

Profile

Bug #9759 » tracepoint_missing_return_bug.rb

deivid (David Rodríguez), 04/19/2014 12:08 PM

 
module Container
end

class Example
def initialize(strategy)
@strategy = strategy
end

def define_method_wrapper
define_method_somewhere_else(@strategy) do |name, &block|
missing_method_to_get_exception
end
end

def define_method_somewhere_else(name, &block)
Container.module_exec do
define_singleton_method(name, &block)
end
end
end

require 'test/unit'

class TestTracePointStacks < Test::Unit::TestCase
def test_missing_return_event
Example.new(:create).define_method_wrapper
events = []
TracePoint.new(:call, :return, :b_call, :b_return, :c_call, :c_return, :raise) do |tp|
events << [tp.event, tp.method_id]
end.enable do
Container.create(:thing) rescue nil
end

[[:b_call, :test_missing_return_event],
[:call, :create],
[:b_call, :create],
[:c_call, :method_missing],
[:c_call, :initialize],
[:c_call, :initialize],
[:c_return, :initialize],
[:c_return, :initialize],
[:c_return, :method_missing],
[:c_call, :exception],
[:c_return, :exception],
[:c_call, :backtrace],
[:c_return, :backtrace],
[:raise, :create],
[:b_return, :create],
[:return, :create],
[:c_call, :===],
[:c_return, :===],
[:b_return, :test_missing_return_event]].zip(events) do |expected, actual|
assert_equal(expected, actual)
end
end
end
    (1-1/1)