Project

General

Profile

Bug #5614 ยป proc_test.rb

ngtzeyang (TzeYang Ng), 11/11/2011 02:17 PM

 
require 'minitest/unit'
require 'minitest/autorun'

class ProcTest < MiniTest::Unit::TestCase

class Foo
class << self

def grab_source_location(&blk)
blk.call(blk.source_location)
self
end

def grab_inspect(&blk)
blk.call(blk.inspect)
self
end
end
end

if Proc.new {}.respond_to?(:source_location)
def test_source_location
line = __LINE__ + 3
results = []

Foo.grab_source_location do |location|
results << location[1]
end.grab_source_location do |location|
results << location[1]
end

assert_equal results[0], line
assert_equal results[1], line + 2
end
end

def test_inspect
line = __LINE__ + 3
results = []

Foo.grab_inspect do |line|
results << line
end.grab_inspect do |line|
results << line
end

assert_match results[0], /:#{line}/
assert_match results[1], /:#{line + 2}/
end

end
    (1-1/1)