Skip to content

Instantly share code, notes, and snippets.

@a2ikm
Last active December 10, 2020 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a2ikm/b21b023690ff8ef99e738497f59725c7 to your computer and use it in GitHub Desktop.
Save a2ikm/b21b023690ff8ef99e738497f59725c7 to your computer and use it in GitHub Desktop.
line_tracer = TracePoint.new(:line) do |tp|
p [tp.path, tp.lineno]
end
RSpec.configure do |config|
# enable for each test case
config.around do |example|
line_tracer.enable do
example.run
end
end
end
current_id = nil
data = Hash.new { |h, example_id| h[example_id] = [] }
line_tracer = TracePoint.new(:line) do |tp|
if record?(tp.path) # tell if we should record this event or not
data[example_id] << [tp.path, tp.lineno]
end
end
RSpec.configure do |config|
config.around do |example|
current_id = example.id
line_tracer.enable do
example.run
end
flush(data) # write and clear huge data on each test case
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment