mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
play -m now uses eval_string.replace() instead of changing Pry#input
This is simpler and more transparent. Also added to this commit is `show-input` now invoked immediately after a `play -m meth --open` (this was only possible because of the eval_string change). Tests for `play` method also updated to reflect changes.
This commit is contained in:
parent
487796348f
commit
0200f1b6f4
2 changed files with 17 additions and 7 deletions
|
@ -79,7 +79,8 @@ e.g amend-line puts 'hello again' # no line number modifies immediately preced
|
||||||
range = opts.l? ? one_index_range_or_number(opts[:l]) : (0..-1)
|
range = opts.l? ? one_index_range_or_number(opts[:l]) : (0..-1)
|
||||||
range = (0..-2) if opts.o?
|
range = (0..-2) if opts.o?
|
||||||
|
|
||||||
_pry_.input = StringIO.new(Array(code.each_line.to_a[range]).join)
|
eval_string.replace((code.each_line.to_a[range]).join)
|
||||||
|
run "show-input" if opts.o?
|
||||||
elsif opts.f?
|
elsif opts.f?
|
||||||
file_name = File.expand_path(opts[:f])
|
file_name = File.expand_path(opts[:f])
|
||||||
next output.puts "No such file: #{opts[:f]}" if !File.exists?(file_name)
|
next output.puts "No such file: #{opts[:f]}" if !File.exists?(file_name)
|
||||||
|
|
|
@ -186,17 +186,26 @@ describe "Pry::DefaultCommands::Input" do
|
||||||
|
|
||||||
it 'should play a method with the -m switch (multiple line)' do
|
it 'should play a method with the -m switch (multiple line)' do
|
||||||
$o = Object.new
|
$o = Object.new
|
||||||
def $o.test_method
|
class << $o
|
||||||
1 + 102
|
attr_accessor :var1, :var2
|
||||||
5 * 6
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def $o.test_method
|
||||||
|
@var1 = 20
|
||||||
|
@var2 = 30
|
||||||
|
end
|
||||||
|
|
||||||
|
obj = Object.new
|
||||||
|
b = Pry.binding_for(obj)
|
||||||
|
|
||||||
redirect_pry_io(InputTester.new('play -m $o.test_method --lines 2..3', "exit-all"), str_output = StringIO.new) do
|
redirect_pry_io(InputTester.new('play -m $o.test_method --lines 2..3', "exit-all"), str_output = StringIO.new) do
|
||||||
pry
|
b.pry
|
||||||
end
|
end
|
||||||
|
|
||||||
str_output.string.should =~ /103\n.*30/
|
obj.instance_variable_get(:@var1).should == 20
|
||||||
$o = nil
|
obj.instance_variable_get(:@var2).should == 30
|
||||||
|
str_output.string.should =~ /30/
|
||||||
|
str_output.string.should.not =~ /20/
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue