Class: PryTester
- Extended by:
- Pry::Forwardable
- Defined in:
- lib/pry/test/helper.rb
Instance Attribute Summary collapse
-
#out ⇒ Object
readonly
Returns the value of attribute out.
-
#pry ⇒ Object
readonly
Returns the value of attribute pry.
Instance Method Summary collapse
- #eval(*strs) ⇒ Object
-
#initialize(target = TOPLEVEL_BINDING, options = {}) ⇒ PryTester
constructor
A new instance of PryTester.
- #last_command_result ⇒ Object
- #last_output ⇒ Object
- #process_command(command_str) ⇒ Object
- #push(*lines) ⇒ Object
- #push_binding(context) ⇒ Object
Methods included from Pry::Forwardable
Constructor Details
#initialize(target = TOPLEVEL_BINDING, options = {}) ⇒ PryTester
Returns a new instance of PryTester.
111 112 113 114 115 116 117 |
# File 'lib/pry/test/helper.rb', line 111 def initialize(target = TOPLEVEL_BINDING, = {}) @pry = Pry.new(.merge(:target => target)) @history = [:history] @pry.inject_sticky_locals! reset_output end |
Instance Attribute Details
#out ⇒ Object (readonly)
Returns the value of attribute out.
107 108 109 |
# File 'lib/pry/test/helper.rb', line 107 def out @out end |
#pry ⇒ Object (readonly)
Returns the value of attribute pry.
107 108 109 |
# File 'lib/pry/test/helper.rb', line 107 def pry @pry end |
Instance Method Details
#eval(*strs) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/pry/test/helper.rb', line 119 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 ⇒ Object
159 160 161 162 |
# File 'lib/pry/test/helper.rb', line 159 def last_command_result result = Pry.current[:pry_cmd_result] result.retval if result end |
#last_output ⇒ Object
150 151 152 |
# File 'lib/pry/test/helper.rb', line 150 def last_output @out.string if @out end |
#process_command(command_str) ⇒ Object
154 155 156 157 |
# File 'lib/pry/test/helper.rb', line 154 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
140 141 142 143 144 |
# File 'lib/pry/test/helper.rb', line 140 def push(*lines) Array(lines).flatten.each do |line| @pry.eval(line) end end |
#push_binding(context) ⇒ Object
146 147 148 |
# File 'lib/pry/test/helper.rb', line 146 def push_binding(context) @pry.push_binding context end |