Sha256: 449c8f9d243d3a7d16119398272d99f86f15312c59eccd137c8a299adbfa26b2

Contents?: true

Size: 1009 Bytes

Versions: 2

Compression:

Stored size: 1009 Bytes

Contents

#!/usr/bin/env ruby
require 'test/unit'
require 'ruby-prof'

# Need to use wall time for this test due to the sleep calls
RubyProf::measure_mode = RubyProf::WALL_TIME

module Foo
  def Foo::hello
    sleep(0.5)
  end
end

module Bar
  def Bar::hello
    sleep(0.5)
    Foo::hello
  end

  def hello
    sleep(0.5)
    Bar::hello
  end
end

include Bar

class ModuleTest < Test::Unit::TestCase
  def test_nested_modules
    result = RubyProf.profile do
      hello
    end

    methods = result.threads.values.first.sort.reverse

    # Length should be 5
    assert_equal(5, methods.length)

    method = methods[0]
    assert_equal('ModuleTest#test_nested_modules', method.full_name)

    method = methods[1]
    assert_equal('Bar#hello', method.full_name)

    method = methods[2]
    assert_equal('Kernel#sleep', method.full_name)

    method = methods[3]
    assert_equal('<Module::Bar>#hello', method.full_name)

    method = methods[4]
    assert_equal('<Module::Foo>#hello', method.full_name)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ruby-prof-0.9.1 test/module_test.rb
ruby-prof-0.9.0 test/module_test.rb