Class: Pry::Testable::PryTester
- Extended by:
- Forwardable
- Defined in:
- lib/pry/testable/pry_tester.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 Forwardable
Constructor Details
#initialize(target = TOPLEVEL_BINDING, options = {}) ⇒ PryTester
Returns a new instance of PryTester.
12 13 14 15 16 17 |
# File 'lib/pry/testable/pry_tester.rb', line 12 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.
9 10 11 |
# File 'lib/pry/testable/pry_tester.rb', line 9 def out @out end |
#pry ⇒ Object (readonly)
Returns the value of attribute pry.
9 10 11 |
# File 'lib/pry/testable/pry_tester.rb', line 9 def pry @pry end |
Instance Method Details
#eval(*strs) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/pry/testable/pry_tester.rb', line 19 def eval(*strs) reset_output result = nil strs.flatten.each do |str| # Check for space prefix. See #1369. str = "#{str.strip}\n" if str !~ /^\s\S/ @history.push str if @history result = if @pry.process_command(str) last_command_result_or_output else # Check if this is a multiline paste. begin complete_expr = Pry::Code.complete_expression?(str) rescue SyntaxError => exception @pry.output.puts( "SyntaxError: #{exception..sub(/.*syntax error, */m, '')}" ) end @pry.evaluate_ruby(str) if complete_expr end end result end |
#last_command_result ⇒ Object
66 67 68 69 |
# File 'lib/pry/testable/pry_tester.rb', line 66 def last_command_result result = Pry.current[:pry_cmd_result] result.retval if result end |
#last_output ⇒ Object
57 58 59 |
# File 'lib/pry/testable/pry_tester.rb', line 57 def last_output @out.string if @out end |
#process_command(command_str) ⇒ Object
61 62 63 64 |
# File 'lib/pry/testable/pry_tester.rb', line 61 def process_command(command_str) @pry.process_command(command_str) || raise("Not a valid command") last_command_result_or_output end |
#push(*lines) ⇒ Object
47 48 49 50 51 |
# File 'lib/pry/testable/pry_tester.rb', line 47 def push(*lines) Array(lines).flatten.each do |line| @pry.eval(line) end end |
#push_binding(context) ⇒ Object
53 54 55 |
# File 'lib/pry/testable/pry_tester.rb', line 53 def push_binding(context) @pry.push_binding context end |