Module: PryTestCase::CommandHelpers
- Defined in:
- lib/pry_test_case/command_helpers.rb
Overview
Mixin providing methods for executing Pry commands in various contexts and environments.
Instance Method Summary collapse
-
#command_exec_cli(command_string, options = {}) ⇒ Object
Evaluates the given command string as the Pry CLI would evaluate it.
-
#command_exec_direct(command_string, options = {}) ⇒ Object
Evaluates the given command string and runs the command directly without going through the Pry CLI eval cycle.
Instance Method Details
#command_exec_cli(command_string, options = {}) ⇒ Object
Evaluates the given command string as the Pry CLI would evaluate it. Behaves more like executing the given command in a live Pry session would. This means that Pry will intercept some behaviors that may be valuable to your tests. For more direct access to the results and errors of a command execution, see #command_exec_direct.
27 28 29 30 31 |
# File 'lib/pry_test_case/command_helpers.rb', line 27 def command_exec_cli(command_string, = {}) Pry.run_command(command_string, ) result = Pry.current[:pry_cmd_result] result && result.retval != Pry::Command::VOID_VALUE ? result.retval : result end |
#command_exec_direct(command_string, options = {}) ⇒ Object
Evaluates the given command string and runs the command directly without going through the Pry CLI eval cycle. Allows more direct access to errors and other things the CLI can make hard to get direct access to. To execute a command in an environment more similar to a live Pry session, see #command_exec_cli.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/pry_test_case/command_helpers.rb', line 56 def command_exec_direct(command_string, = {}) = { :target => TOPLEVEL_BINDING, :output => Pry.config.output, :command_set => Pry.config.commands, }.merge!() [:eval_string] = command_string [:pry_instance] ||= Pry.new({ :target => [:target], :output => [:output], :commands => [:command_set], }) args = command_string.split(/\s+/) match = args.shift Pry.commands.run_command(, match, *args) end |