Project

General

Profile

Bug #9759 » tracepoint_missing_return_bug.rb

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

 
1
module Container
2
end
3

    
4
class Example
5
  def initialize(strategy)
6
    @strategy = strategy
7
  end
8

    
9
  def define_method_wrapper
10
    define_method_somewhere_else(@strategy) do |name, &block|
11
      missing_method_to_get_exception
12
    end
13
  end
14

    
15
  def define_method_somewhere_else(name, &block)
16
    Container.module_exec do
17
      define_singleton_method(name, &block)
18
    end
19
  end
20
end
21

    
22
require 'test/unit'
23

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

    
34
    [[:b_call, :test_missing_return_event],
35
     [:call, :create],
36
     [:b_call, :create],
37
     [:c_call, :method_missing],
38
     [:c_call, :initialize],
39
     [:c_call, :initialize],
40
     [:c_return, :initialize],
41
     [:c_return, :initialize],
42
     [:c_return, :method_missing],
43
     [:c_call, :exception],
44
     [:c_return, :exception],
45
     [:c_call, :backtrace],
46
     [:c_return, :backtrace],
47
     [:raise, :create],
48
     [:b_return, :create],
49
     [:return, :create],
50
     [:c_call, :===],
51
     [:c_return, :===],
52
     [:b_return, :test_missing_return_event]].zip(events) do |expected, actual|
53
       assert_equal(expected, actual)
54
     end
55
  end
56
end