diff --git a/spec/commands/edit_spec.rb b/spec/commands/edit_spec.rb index 1f23f09b..beeaf9b3 100644 --- a/spec/commands/edit_spec.rb +++ b/spec/commands/edit_spec.rb @@ -1,3 +1,4 @@ +require 'pathname' require 'helper' describe "edit" do @@ -15,13 +16,25 @@ describe "edit" do end describe "with FILE" do + before do + # OS-specific tempdir name. For GNU/Linux it's "tmp", for Windows it's + # something "Temp". + @tf_dir = Pathname.new(Dir::Tmpname.tmpdir) + + @tf_path = File.expand_path(File.join(@tf_dir.to_s, 'bar.rb')) + FileUtils.touch(@tf_path) + end + + after do + FileUtils.rm(@tf_path) if File.exists?(@tf_path) + end + it "should invoke Pry.config.editor with absolutified filenames" do pry_eval 'edit lib/pry.rb' @file.should == File.expand_path('lib/pry.rb') - FileUtils.touch '/tmp/bar.rb' - pry_eval 'edit /tmp/bar.rb' - @file.should == '/tmp/bar.rb' + pry_eval "edit #@tf_path" + @file.should == @tf_path end it "should guess the line number from a colon" do @@ -40,9 +53,11 @@ describe "edit" do end it "works with files that contain blanks in their names" do - FileUtils.touch '/tmp/hello world.rb' - pry_eval 'edit /tmp/hello world.rb' - @file.should == '/tmp/hello world.rb' + tf_path = File.join(File.dirname(@tf_path), 'swoop and doop.rb') + FileUtils.touch(tf_path) + pry_eval "edit #{ tf_path }" + @file.should == tf_path + FileUtils.rm(tf_path) end describe do diff --git a/spec/editor_spec.rb b/spec/editor_spec.rb index 76533524..1c2b4562 100644 --- a/spec/editor_spec.rb +++ b/spec/editor_spec.rb @@ -11,7 +11,7 @@ describe Pry::Editor do # something "Temp". @tf_dir = Pathname.new(Dir::Tmpname.tmpdir) - @tf_path = @tf_dir.to_s + File::SEPARATOR + 'hello world.rb' + @tf_path = File.join(@tf_dir.to_s, 'hello world.rb') end unless Pry::Helpers::BaseHelpers.windows? @@ -68,7 +68,7 @@ describe Pry::Editor do it 'should not shell-escape files' do Pry::Editor.invoke_editor(@tf_path, 10, true) - @file.should == "#@tf_path" + @file.should == @tf_path end end end