class PryTester

def context=(context)

def context=(context)
  @pry.binding_stack << Pry.binding_for(context)
end

def eval(*strs)

def eval(*strs)
  reset_output
  result = nil
  strs.flatten.each do |str|
    str = "#{str.strip}\n"
    if @pry.process_command(str)
      result = last_command_result_or_output
    else
      result = @pry.evaluate_ruby(str)
    end
  end
  result
end

def initialize(context = TOPLEVEL_BINDING, options = {})

def initialize(context = TOPLEVEL_BINDING, options = {})
  @pry = Pry.new(options)
  if context
    target = Pry.binding_for(context)
    @pry.binding_stack << target
    @pry.inject_sticky_locals(target)
  end
  @pry.input_array << nil # TODO: shouldn't need this
  reset_output
end

def last_command_result

def last_command_result
  result = Pry.current[:pry_cmd_result]
  result.retval if result
end

def last_command_result_or_output

def last_command_result_or_output
  result = last_command_result
  if result != Pry::Command::VOID_VALUE
    result
  else
    last_output
  end
end

def last_output

def last_output
  @out.string if @out
end

def process_command(command_str, eval_str = '')

def process_command(command_str, eval_str = '')
  @pry.process_command(command_str, eval_str) or raise "Not a valid command"
  last_command_result_or_output
end

def reset_output

def reset_output
  @out = StringIO.new
  @pry.output = @out
end

def simulate_repl

TODO: eliminate duplication with Pry#repl
def simulate_repl
  didnt_exit = nil
  break_data = nil
  didnt_exit = catch(:didnt_exit) do
    break_data = catch(:breakout) do
      yield self
      throw(:didnt_exit, true)
    end
    nil
  end
  raise "Failed to exit REPL" if didnt_exit
  break_data
end