1
0
Fork 0
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:
John Mair 2011-09-12 04:26:38 +12:00
parent 487796348f
commit 0200f1b6f4
2 changed files with 17 additions and 7 deletions

View file

@ -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 = (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?
file_name = File.expand_path(opts[:f])
next output.puts "No such file: #{opts[:f]}" if !File.exists?(file_name)

View file

@ -186,17 +186,26 @@ describe "Pry::DefaultCommands::Input" do
it 'should play a method with the -m switch (multiple line)' do
$o = Object.new
def $o.test_method
1 + 102
5 * 6
class << $o
attr_accessor :var1, :var2
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
pry
b.pry
end
str_output.string.should =~ /103\n.*30/
$o = nil
obj.instance_variable_get(:@var1).should == 20
obj.instance_variable_get(:@var2).should == 30
str_output.string.should =~ /30/
str_output.string.should.not =~ /20/
end
end