Sha256: ec1c420f89ce2fb8464ec3fccd4f4c9f00ab8adb529901b0d805a6db3e318f1c
Contents?: true
Size: 1.84 KB
Versions: 2
Compression:
Stored size: 1.84 KB
Contents
module PryDebugger module Breakpoints def breakpoints(breakpoints) breakpoints.each_with_index do |b, index| next_b = breakpoints[index+1] b[0] = next_b ? next_b[0] : nil end PryDebugger.breakpoints = breakpoints.map do |b| Proc.new do |label, binding_, output| compare(b[1], label, binding_, output) b[0] end end end def compare(subj, label, binding_, output) if subj.is_a? Proc subj.call binding_, output elsif subj.is_a? Hash if subj[:out_includes] expect(output).to include subj[:out_includes] else expect(output).to eq subj[:out] end elsif not subj.nil? expect(label).to eq subj end end end class InputPipe def readline(*args) repl_binding = binding.callers[1] pry_ = repl_binding.eval('@pry') binding_ = pry_.current_binding next_cmd = PryDebugger.enter_breakpoint binding_ next_cmd || 'c' end end class OutputPipe < StringIO def print(*args) #STDOUT.print *args super end def take_away result = string.clone truncate(0) rewind result.gsub(/\e\[([;\d]+)?m/, '') end end extend self def inject Pry.config.input = InputPipe.new @output = OutputPipe.new Pry.config.output = @output end def breakpoints @breakpoints_procs end def breakpoints=(breakpoints) @breakpoints_procs = breakpoints @breakpoint_call = 0 end def enter_breakpoint(binding_) raise 'Next breakpoint handler missing' if @breakpoints_procs.size == 0 #puts (@breakpoint_call += 1) output = @output.take_away output.match(/^ => .*#(.*)/) label = ($1 || '').strip @breakpoints_procs.shift.call label, binding_, output.strip end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
pry-moves-0.1.6 | spec/pry_debugger.rb |
pry-moves-0.1.5 | spec/pry_debugger.rb |