diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index 68acb933..6de154ec 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -35,6 +35,7 @@ class Pry attr_accessor :custom_completions attr_accessor :binding_stack + attr_accessor :eval_string attr_accessor :last_result attr_accessor :last_file diff --git a/lib/pry/test/helper.rb b/lib/pry/test/helper.rb index 9543920a..061dceca 100644 --- a/lib/pry/test/helper.rb +++ b/lib/pry/test/helper.rb @@ -101,8 +101,12 @@ def pry_eval(*eval_strs) end class PryTester + extend Forwardable + attr_reader :pry, :out + def_delegators :@pry, :eval_string, :eval_string=, :accept_line + def initialize(target = TOPLEVEL_BINDING, options = {}) @pry = Pry.new(options.merge(:target => target)) @history = options[:history] @@ -130,6 +134,10 @@ class PryTester result end + def accept_lines(*lines) + lines.each(&method(:accept_line)) + end + def push_binding(context) @pry.push_binding context end @@ -155,8 +163,8 @@ class PryTester @out.string if @out end - def process_command(command_str, eval_str = '') - @pry.process_command(command_str, eval_str) or raise "Not a valid command" + def process_command(command_str) + @pry.process_command(command_str) or raise "Not a valid command" last_command_result_or_output end diff --git a/spec/commands/amend_line_spec.rb b/spec/commands/amend_line_spec.rb index 62a59e7e..4174bed6 100644 --- a/spec/commands/amend_line_spec.rb +++ b/spec/commands/amend_line_spec.rb @@ -6,29 +6,29 @@ describe "amend-line" do end it 'should amend the last line of input when no line number specified' do - eval_str = unindent(<<-STR) + @t.accept_lines *unindent(<<-STR).split("\n") def hello puts :bing STR - @t.process_command 'amend-line puts :blah', eval_str + @t.process_command 'amend-line puts :blah' - eval_str.should == unindent(<<-STR) + @t.eval_string.should == unindent(<<-STR) def hello puts :blah STR end it 'should amend the specified line of input when line number given' do - eval_str = unindent(<<-STR) + @t.accept_lines *unindent(<<-STR).split("\n") def hello puts :bing puts :bang STR - @t.process_command 'amend-line 1 def goodbye', eval_str + @t.process_command 'amend-line 1 def goodbye' - eval_str.should == unindent(<<-STR) + @t.eval_string.should == unindent(<<-STR) def goodbye puts :bing puts :bang @@ -36,15 +36,15 @@ describe "amend-line" do end it 'should amend the first line of input when 0 given as line number' do - eval_str = unindent(<<-STR) + @t.accept_lines *unindent(<<-STR).split("\n") def hello puts :bing puts :bang STR - @t.process_command 'amend-line 0 def goodbye', eval_str + @t.process_command 'amend-line 0 def goodbye' - eval_str.should == unindent(<<-STR) + @t.eval_string.should == unindent(<<-STR) def goodbye puts :bing puts :bang @@ -52,23 +52,23 @@ describe "amend-line" do end it 'should amend a specified line when negative number given' do - eval_str = unindent(<<-STR) + @t.accept_lines *unindent(<<-STR).split("\n") def hello puts :bing puts :bang STR - @t.process_command 'amend-line -1 puts :bink', eval_str + @t.process_command 'amend-line -1 puts :bink' - eval_str.should == unindent(<<-STR) + @t.eval_string.should == unindent(<<-STR) def hello puts :bing puts :bink STR - @t.process_command 'amend-line -2 puts :bink', eval_str + @t.process_command 'amend-line -2 puts :bink' - eval_str.should == unindent(<<-STR) + @t.eval_string.should == unindent(<<-STR) def hello puts :bink puts :bink @@ -76,16 +76,16 @@ describe "amend-line" do end it 'should amend a range of lines of input when negative numbers given' do - eval_str = unindent(<<-STR) + @t.accept_lines *unindent(<<-STR).split("\n") def hello puts :bing puts :bang puts :boat STR - @t.process_command 'amend-line -3..-2 puts :bink', eval_str + @t.process_command 'amend-line -3..-2 puts :bink' - eval_str.should == unindent(<<-STR) + @t.eval_string.should == unindent(<<-STR) def hello puts :bink puts :boat @@ -93,15 +93,15 @@ describe "amend-line" do end it 'should correctly amend the specified line with interpolated text' do - eval_str = unindent(<<-STR) + @t.accept_lines *unindent(<<-STR).split("\n") def hello puts :bing puts :bang STR - @t.process_command 'amend-line puts "#{goodbye}"', eval_str + @t.process_command 'amend-line puts "#{goodbye}"' - eval_str.should == unindent(<<-'STR') + @t.eval_string.should == unindent(<<-'STR') def hello puts :bing puts "#{goodbye}" @@ -122,16 +122,16 @@ describe "amend-line" do end it 'should correctly amend the specified range of lines' do - eval_str = unindent(<<-STR) + @t.accept_lines *unindent(<<-STR).split("\n") def hello puts :bing puts :bang puts :heart STR - @t.process_command 'amend-line 2..3 puts :bong', eval_str + @t.process_command 'amend-line 2..3 puts :bong' - eval_str.should == unindent(<<-STR) + @t.eval_string.should == unindent(<<-STR) def hello puts :bong puts :heart @@ -139,7 +139,7 @@ describe "amend-line" do end it 'should correctly delete a specific line using the ! for content' do - eval_str = unindent(<<-STR) + @t.accept_lines *unindent(<<-STR).split("\n") def hello puts :bing puts :bang @@ -147,9 +147,9 @@ describe "amend-line" do puts :heart STR - @t.process_command 'amend-line 3 !', eval_str + @t.process_command 'amend-line 3 !' - eval_str.should == unindent(<<-STR) + @t.eval_string.should == unindent(<<-STR) def hello puts :bing puts :boast @@ -158,7 +158,7 @@ describe "amend-line" do end it 'should correctly delete a range of lines using the ! for content' do - eval_str = unindent(<<-STR) + @t.accept_lines *unindent(<<-STR).split("\n") def hello puts :bing puts :bang @@ -166,16 +166,16 @@ describe "amend-line" do puts :heart STR - @t.process_command 'amend-line 2..4 !', eval_str + @t.process_command 'amend-line 2..4 !' - eval_str.should == unindent(<<-STR) + @t.eval_string.should == unindent(<<-STR) def hello puts :heart STR end it 'should correctly delete the previous line using the ! for content' do - eval_str = unindent(<<-STR) + @t.accept_lines *unindent(<<-STR).split("\n") def hello puts :bing puts :bang @@ -183,9 +183,9 @@ describe "amend-line" do puts :heart STR - @t.process_command 'amend-line !', eval_str + @t.process_command 'amend-line !' - eval_str.should == unindent(<<-STR) + @t.eval_string.should == unindent(<<-STR) def hello puts :bing puts :bang @@ -194,7 +194,7 @@ describe "amend-line" do end it 'should amend the specified range of lines, with numbers < 0 in range' do - eval_str = unindent(<<-STR) + @t.accept_lines *unindent(<<-STR).split("\n") def hello puts :bing puts :bang @@ -202,9 +202,9 @@ describe "amend-line" do puts :heart STR - @t.process_command 'amend-line 2..-2 puts :bong', eval_str + @t.process_command 'amend-line 2..-2 puts :bong' - eval_str.should == unindent(<<-STR) + @t.eval_string.should == unindent(<<-STR) def hello puts :bong puts :heart @@ -212,15 +212,15 @@ describe "amend-line" do end it 'should correctly insert a line before a specified line using >' do - eval_str = unindent(<<-STR) + @t.accept_lines *unindent(<<-STR).split("\n") def hello puts :bing puts :bang STR - @t.process_command 'amend-line 2 > puts :inserted', eval_str + @t.process_command 'amend-line 2 > puts :inserted' - eval_str.should == unindent(<<-STR) + @t.eval_string.should == unindent(<<-STR) def hello puts :inserted puts :bing @@ -229,15 +229,15 @@ describe "amend-line" do end it 'should ignore second value of range with > syntax' do - eval_str = unindent(<<-STR) + @t.accept_lines *unindent(<<-STR).split("\n") def hello puts :bing puts :bang STR - @t.process_command 'amend-line 2..21 > puts :inserted', eval_str + @t.process_command 'amend-line 2..21 > puts :inserted' - eval_str.should == unindent(<<-STR) + @t.eval_string.should == unindent(<<-STR) def hello puts :inserted puts :bing