class PryTester

Attributes

out[R]
pry[R]

Public Class Methods

new(context = TOPLEVEL_BINDING, options = {}) click to toggle source
# File lib/pry/test/helper.rb, line 106
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

Public Instance Methods

context=(context) click to toggle source
# File lib/pry/test/helper.rb, line 135
def context=(context)
  @pry.binding_stack << Pry.binding_for(context)
end
eval(*strs) click to toggle source
# File lib/pry/test/helper.rb, line 119
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
last_output() click to toggle source
# File lib/pry/test/helper.rb, line 156
def last_output
  @out.string if @out
end
process_command(command_str, eval_str = '') click to toggle source
# File lib/pry/test/helper.rb, line 160
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
simulate_repl() { |self| ... } click to toggle source

TODO: eliminate duplication with Pry#repl

# File lib/pry/test/helper.rb, line 140
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

Protected Instance Methods

last_command_result() click to toggle source
# File lib/pry/test/helper.rb, line 167
def last_command_result
  result = Pry.current[:pry_cmd_result]
  result.retval if result
end
last_command_result_or_output() click to toggle source
# File lib/pry/test/helper.rb, line 172
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/test/helper.rb, line 181
def reset_output
  @out = StringIO.new
  @pry.output = @out
end