diff --git a/test/helper.rb b/test/helper.rb index 4d99346f..2a16b1d7 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -219,19 +219,17 @@ class PryTester if context @pry.binding_stack << Pry.binding_for(context) end + + reset_output end def eval(*strs) - @out = StringIO.new - @pry.output = @out + reset_output result = nil strs.flatten.each do |str| if @pry.process_command(str) - result = last_command_result - if result == Pry::Command::VOID_VALUE - result = last_output - end + result = last_command_result_or_output else result = @pry.evaluate_ruby(str) end @@ -244,12 +242,31 @@ 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" + last_command_result_or_output + end + protected def last_command_result result = Thread.current[:__pry_cmd_result__] result.retval if result end + + def last_command_result_or_output + result = last_command_result + if result != Pry::Command::VOID_VALUE + result + else + last_output + end + end + + def reset_output + @out = StringIO.new + @pry.output = @out + end end CommandTester = Pry::CommandSet.new do @@ -262,6 +279,10 @@ CommandTester = Pry::CommandSet.new do end end +def unindent(*args) + Pry::Helpers::CommandHelpers.unindent(*args) +end + # to help with tracking down bugs that cause an infinite loop in the test suite if ENV["SET_TRACE_FUNC"] require 'set_trace' if Pry::Helpers::BaseHelpers.rbx? diff --git a/test/test_default_commands/test_input.rb b/test/test_default_commands/test_input.rb index 7c27cbd1..071b0058 100644 --- a/test/test_default_commands/test_input.rb +++ b/test/test_default_commands/test_input.rb @@ -3,15 +3,22 @@ require 'helper' describe "Pry::DefaultCommands::Input" do before do @str_output = StringIO.new + @t = pry_tester end describe "amend-line" do it 'should correctly amend the last line of input when no line number specified ' do - redirect_pry_io(InputTester.new("def hello", "puts :bing", "amend-line puts :blah", "show-input", "exit-all"), @str_output) do - pry - end + eval_str = unindent(<<-STR) + def hello + puts :bing + STR - @str_output.string.should =~ /\A\d+: def hello\n\d+: puts :blah/ + @t.process_command 'amend-line puts :blah', eval_str + + eval_str.should == unindent(<<-STR) + def hello + puts :blah + STR end it 'should correctly amend the specified line of input when line number given ' do