Skip to content

Instantly share code, notes, and snippets.

@y-yagi
Created November 9, 2014 06:40
Show Gist options
  • Save y-yagi/cec784b99b56a226e60d to your computer and use it in GitHub Desktop.
Save y-yagi/cec784b99b56a226e60d to your computer and use it in GitHub Desktop.
TracePoint study
require 'minitest'
require "minitest/autorun"
require 'power_p'
require 'ripper'
trace = TracePoint.new(:raise) do |tp|
if tp.raised_exception.class == Minitest::Assertion
file, lineno = tp.raised_exception.location.split(':')
line = open(file).each_line.drop(lineno.to_i - 1).first
idents = Ripper.sexp(line)
p "line: #{line}".strip
# p tp.binding.eval('caller_locations')
# p tp.binding.eval('local_variables')
end
end
trace.enable
class TestMeme < Minitest::Test
def test_that_kitty_can_eat
assert_equal 3.times.to_a, 0
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment