Class: Test::Unit::TestCase

Inherits:
Object
  • Object
show all
Defined in:
lib/shoulda_benchmark.rb

Class Method Summary collapse

Class Method Details

.method_added(name) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/shoulda_benchmark.rb', line 49

def self.method_added(name)
  return if @ignoring_added_methods
  
  test_name = if respond_to?(:name)
                name
              elsif respond_to?(:__name__)
                __name__
              end
  @__instrumented_methods ||= {}
  return unless name.to_s.match(/^test:/) || @__instrumented_methods[name]
  @ignoring_added_methods = true
  alias_method " #{name}", "#{name}"
  @__instrumented_methods[name] = true
  define_method(name) do
    runtime = Benchmark.realtime do
      send(" #{name}")
    end
    Shoulda.runtimes[test_name] = runtime
  end
  @ignoring_added_methods = false
end