class SpeedyRspec::TracingSpy

Public Class Methods

new() click to toggle source
# File lib/speedyrspec/spies.rb, line 7
def initialize
  @datamanager = DependencyManagerFactory.new_dependencies
end

Public Instance Methods

finish() click to toggle source
# File lib/speedyrspec/spies.rb, line 16
def finish
  @datamanager.finish
end
start() click to toggle source
# File lib/speedyrspec/spies.rb, line 11
def start
  puts 'Starting test suite with tracing enabled.'
  @tracer = set_tracer
end
test_ends(example) click to toggle source
# File lib/speedyrspec/spies.rb, line 26
def test_ends(example)
  @tracer.disable
end
test_starts(example) click to toggle source
# File lib/speedyrspec/spies.rb, line 20
def test_starts(example)
  deduce_workingdir(example) unless @working_dir
  @current_test = example.file_path
  @tracer.enable
end

Private Instance Methods

deduce_workingdir(example) click to toggle source
# File lib/speedyrspec/spies.rb, line 32
def deduce_workingdir(example)
  fp = example.metadata[:file_path]
  path = example.metadata[:absolute_file_path]
  @working_dir = path[0, path.index(fp[1, fp.length])]
  @wd_path = Pathname.new(@working_dir)
end
set_tracer() click to toggle source
# File lib/speedyrspec/spies.rb, line 39
def set_tracer
  TracePoint.new(*%i[call b_call]) do |tp|
    unless tp.path.index(@working_dir).nil?
      tp_path = Pathname.new(tp.path)
      rel_path = tp_path.relative_path_from(@wd_path).to_s
      @datamanager.add_dependency(rel_path, @current_test) unless @current_test.index(rel_path)
    end
  end
end