mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Fix Pry.run_command
The problem was that Pry#rep() no longer works on its own, it's necessary to use Pry#repl() instead. This is because many new API, like Pry::CodeObject.lookup now get the target binding directly from the _pry_ instance (Pry#current_context), rather than requiring it to be passed in separately. This saves us a parameter. The reason Pry#rep doesnt work with Pry::CodeObject.lookup (and so show-source/show-doc etc) is that the binding_stack is only set up in Pry#repl_prologue, and it is the binding_stack (via Pry#current_context) that is accessed by Pry::CodeObject and pals.
This commit is contained in:
parent
c10017f17d
commit
aac76dd355
2 changed files with 26 additions and 1 deletions
|
@ -239,7 +239,9 @@ class Pry
|
|||
|
||||
output = options[:show_output] ? options[:output] : StringIO.new
|
||||
|
||||
Pry.new(:output => output, :input => StringIO.new(command_string), :commands => options[:commands], :prompt => proc {""}, :hooks => Pry::Hooks.new).rep(options[:context])
|
||||
Pry.new(:output => output, :input => StringIO.new("#{command_string}\nexit-all\n"),
|
||||
:commands => options[:commands],
|
||||
:prompt => proc {""}, :hooks => Pry::Hooks.new).repl(options[:context])
|
||||
end
|
||||
|
||||
def self.default_editor_for_platform
|
||||
|
|
23
spec/run_command_spec.rb
Normal file
23
spec/run_command_spec.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
require 'helper'
|
||||
|
||||
describe "Pry.run_command" do
|
||||
before do
|
||||
o = Object.new
|
||||
def o.drum
|
||||
"roken is dodelijk"
|
||||
end
|
||||
@context = Pry.binding_for(o)
|
||||
end
|
||||
|
||||
it 'performs a simple ls' do
|
||||
@context.eval("hokey_pokey = 10")
|
||||
Pry.run_command "ls", :context => @context, :output => out = StringIO.new
|
||||
out.string.should =~ /hokey_pokey/
|
||||
end
|
||||
|
||||
# This is a regression test as 0.9.11 broke this behaviour
|
||||
it 'can perform a show-source' do
|
||||
Pry.run_command "show-source drum", :context => @context, :output => out = StringIO.new
|
||||
out.string.should =~ /roken is dodelijk/
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue