Class: PryTester

Inherits:
Object show all
Extended by:
Forwardable
Defined in:
lib/pry/test/helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of PryTester.



105
106
107
108
109
110
111
# File 'lib/pry/test/helper.rb', line 105

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.



101
102
103
# File 'lib/pry/test/helper.rb', line 101

def out
  @out
end

#pryObject (readonly)

Returns the value of attribute pry.



101
102
103
# File 'lib/pry/test/helper.rb', line 101

def pry
  @pry
end

Instance Method Details

#eval(*strs) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/pry/test/helper.rb', line 113

def eval(*strs)
  reset_output
  result = nil

  strs.flatten.each do |str|
    str = "#{str.strip}\n"
    @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



150
151
152
153
# File 'lib/pry/test/helper.rb', line 150

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

#last_outputObject



141
142
143
# File 'lib/pry/test/helper.rb', line 141

def last_output
  @out.string if @out
end

#process_command(command_str) ⇒ Object



145
146
147
148
# File 'lib/pry/test/helper.rb', line 145

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



131
132
133
134
135
# File 'lib/pry/test/helper.rb', line 131

def push(*lines)
  Array(lines).flatten.each do |line|
    @pry.eval(line)
  end
end

#push_binding(context) ⇒ Object



137
138
139
# File 'lib/pry/test/helper.rb', line 137

def push_binding(context)
  @pry.push_binding context
end