Class: Pry::Testable::PryTester

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/pry/testable/pry_tester.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Forwardable

def_private_delegators

Constructor Details

#initialize(target = TOPLEVEL_BINDING, options = {}) ⇒ PryTester

Returns a new instance of PryTester



6
7
8
9
10
11
# 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

Instance Attribute Details

#outObject (readonly)

Returns the value of attribute out



3
4
5
# File 'lib/pry/testable/pry_tester.rb', line 3

def out
  @out
end

#pryObject (readonly)

Returns the value of attribute pry



3
4
5
# File 'lib/pry/testable/pry_tester.rb', line 3

def pry
  @pry
end

Instance Method Details

#eval(*strs) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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_resultObject



53
54
55
56
# 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_outputObject



44
45
46
# File 'lib/pry/testable/pry_tester.rb', line 44

def last_output
  @out.string if @out
end

#process_command(command_str) ⇒ Object



48
49
50
51
# 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) ⇒ Object



34
35
36
37
38
# 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) ⇒ Object



40
41
42
# File 'lib/pry/testable/pry_tester.rb', line 40

def push_binding(context)
  @pry.push_binding context
end