1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

added a Pry#run_command method

Useful when pry instance is passed to procs such as exception handlers
e.g Pry.config.exception_handler = proc |output, value, _pry_|
      _pry_.run_command('cat --ex')
    end

Notw that run_command also accepts a optional second parameter 'binding' that defaults to binding_stack.last when not given
This commit is contained in:
John Mair 2011-09-11 04:41:51 +12:00
parent 7878654d42
commit 06991b221a
2 changed files with 23 additions and 0 deletions

View file

@ -319,6 +319,16 @@ class Pry
end
end
# Run the specified command.
# @param [String] The command (and its params) to execute.
# @param [Binding] The binding to use..
# @example
# pry_instance.run_command("ls -m")
def run_command(val, target = binding_stack.last)
process_line(val, "", target)
Pry::CommandContext::VOID_VALUE
end
# Set the last result of an eval.
# This method should not need to be invoked directly.
# @param [Object] result The result.

View file

@ -187,6 +187,19 @@ describe Pry do
end
end
describe "Pry#run_command" do
it 'should run a command in a specified context' do
b = Pry.binding_for(7)
p = Pry.new(:output => StringIO.new)
p.run_command("ls -m", b)
p.output.string.should =~ /divmod/
end
it 'should run a command in the context of a session' do
mock_pry("@session_ivar = 10", "_pry_.run_command('ls')").should =~ /@session_ivar/
end
end
describe "repl" do
describe "basic functionality" do
it 'should set an ivar on an object and exit the repl' do