diff --git a/lib/pry.rb b/lib/pry.rb index f4832a4b..b37dc082 100644 --- a/lib/pry.rb +++ b/lib/pry.rb @@ -17,7 +17,7 @@ class Pry end } - # The default prints + # The default print DEFAULT_PRINT = proc do |output, value| stringified = begin value.pretty_inspect @@ -57,7 +57,7 @@ class Pry if nest_level == 0 "pry(#{Pry.view_clip(target_self)})> " else - "pry(#{Pry.view_clip(target_self)}):#{Pry.view_clip(nest_level)}> " + "pry(#{Pry.view_clip(target_self)}):#{nest_level}> " end }, @@ -65,7 +65,7 @@ class Pry if nest_level == 0 "pry(#{Pry.view_clip(target_self)})* " else - "pry(#{Pry.view_clip(target_self)}):#{Pry.view_clip(nest_level)}* " + "pry(#{Pry.view_clip(target_self)}):#{nest_level}* " end } ] diff --git a/lib/pry/default_commands/introspection.rb b/lib/pry/default_commands/introspection.rb index 6afba45d..a2684ad4 100644 --- a/lib/pry/default_commands/introspection.rb +++ b/lib/pry/default_commands/introspection.rb @@ -146,8 +146,9 @@ class Pry should_reload_at_top_level = opts[:n] ? false : true elsif opts.t? || args.first.nil? - file_name = Tempfile.new(["tmp", ".rb"]).tap(&:close).path - File.open(file_name, "w") { |f| f.puts eval_string } if !eval_string.empty? + file_name = temp_file do |f| + f.puts eval_string if !eval_string.empty? + end line = eval_string.lines.count + 1 should_reload_locally = opts[:n] ? false : true else diff --git a/lib/pry/helpers/command_helpers.rb b/lib/pry/helpers/command_helpers.rb index b0957a54..dfc4a467 100644 --- a/lib/pry/helpers/command_helpers.rb +++ b/lib/pry/helpers/command_helpers.rb @@ -39,6 +39,16 @@ class Pry end end + # Open a temp file and yield it to the block, closing it after + # @return [String] The path of the temp file + def temp_file + file = Tempfile.new(["tmp", ".rb"]) + yield file + file.path + ensure + file.close + end + ########### RBX HELPERS ############# def is_core_rbx_path?(path) rbx? && diff --git a/test/test_pry.rb b/test/test_pry.rb index d9d502a2..3c7f6f1e 100644 --- a/test/test_pry.rb +++ b/test/test_pry.rb @@ -1135,12 +1135,12 @@ describe Pry do end end - # describe "given the 'main' object" do - # it "returns the #inspect of main (special case)" do - # o = TOPLEVEL_BINDING.eval('self') - # Pry.view_clip(o, VC_MAX_LENGTH).should == o.inspect - # end - # end + describe "given the 'main' object" do + it "returns the #inspect of main (special case)" do + o = TOPLEVEL_BINDING.eval('self') + Pry.view_clip(o, VC_MAX_LENGTH).should == o.inspect + end + end describe "given an object with an #inspect string as long as the maximum specified" do it "returns the #<> format of the object (never use inspect)" do diff --git a/test/test_pry_history.rb b/test/test_pry_history.rb index fc46e383..2d0c9b07 100644 --- a/test/test_pry_history.rb +++ b/test/test_pry_history.rb @@ -5,7 +5,8 @@ describe Pry do before do Pry.history.clear - @hist = Tempfile.new(["tmp", ".pry_history"]).tap(&:close).path + @file = Tempfile.new(["tmp", ".pry_history"]) + @hist = @file.path File.open(@hist, 'w') {|f| f << "1\n2\n3\n" } @old_hist = Pry.config.history.file Pry.config.history.file = @hist @@ -13,7 +14,8 @@ describe Pry do end after do - File.unlink @hist + @file.close + File.unlink(@hist) Pry.config.history.file = @old_hist end