Class: PryTester
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
Constructor Details
#initialize(target = TOPLEVEL_BINDING, options = {}) ⇒ PryTester
Returns a new instance of PryTester.
8 9 10 11 12 13 14 |
# File 'lib/pry_tester.rb', line 8 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.
4 5 6 |
# File 'lib/pry_tester.rb', line 4 def out @out end |
#pry ⇒ Object (readonly)
Returns the value of attribute pry.
4 5 6 |
# File 'lib/pry_tester.rb', line 4 def pry @pry end |
Instance Method Details
#eval(*strs) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/pry_tester.rb', line 16 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
56 57 58 59 |
# File 'lib/pry_tester.rb', line 56 def last_command_result result = Pry.current[:pry_cmd_result] result.retval if result end |
#last_output ⇒ Object
47 48 49 |
# File 'lib/pry_tester.rb', line 47 def last_output @out.string if @out end |
#process_command(command_str) ⇒ Object
51 52 53 54 |
# File 'lib/pry_tester.rb', line 51 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
37 38 39 40 41 |
# File 'lib/pry_tester.rb', line 37 def push(*lines) Array(lines).flatten.each do |line| @pry.eval(line) end end |
#push_binding(context) ⇒ Object
43 44 45 |
# File 'lib/pry_tester.rb', line 43 def push_binding(context) @pry.push_binding context end |