class Pry::Testable::PryTester

Attributes

out[R]
pry[R]

Public Class Methods

new(target = TOPLEVEL_BINDING, options = {}) click to toggle source
# File lib/pry/testable/pry_tester.rb, line 6
def initialize(target = TOPLEVEL_BINDING, options = {})
  @pry = Pry.new(options.merge(target: target))
  @history = options[:history]
  @pry.inject_sticky_locals!
  reset_output
end

Public Instance Methods

eval(*strs) click to toggle source
# File lib/pry/testable/pry_tester.rb, line 13
def eval(*strs)
  reset_output
  result = nil

  strs.flatten.each do |str|
    # Check for space prefix. See #1369.
    if str !~ /^\s\S/
      str = "#{str.strip}\n"
    end
    @history.push str if @history

    if @pry.process_command(str)
      result = last_command_result_or_output
    else
      result = @pry.evaluate_ruby(str)
    end
  end

  result
end
last_command_result() click to toggle source
# File lib/pry/testable/pry_tester.rb, line 53
def last_command_result
  result = Pry.current[:pry_cmd_result]
  result.retval if result
end
last_output() click to toggle source
# File lib/pry/testable/pry_tester.rb, line 44
def last_output
  @out.string if @out
end
process_command(command_str) click to toggle source
# File lib/pry/testable/pry_tester.rb, line 48
def process_command(command_str)
  @pry.process_command(command_str) or raise "Not a valid command"
  last_command_result_or_output
end
push(*lines) click to toggle source
# File lib/pry/testable/pry_tester.rb, line 34
def push(*lines)
  Array(lines).flatten.each do |line|
    @pry.eval(line)
  end
end
push_binding(context) click to toggle source
# File lib/pry/testable/pry_tester.rb, line 40
def push_binding(context)
  @pry.push_binding context
end

Protected Instance Methods

last_command_result_or_output() click to toggle source
# File lib/pry/testable/pry_tester.rb, line 60
def last_command_result_or_output
  result = last_command_result
  if result != Pry::Command::VOID_VALUE
    result
  else
    last_output
  end
end
reset_output() click to toggle source
# File lib/pry/testable/pry_tester.rb, line 69
def reset_output
  @out = StringIO.new
  @pry.output = @out
end