1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Fix errors in tests on Windows

Some tests are still failing, though. This commit fixes wrong usage of
temporary paths on Windows. Please, note: the `edit` command is working
well; the issue is in poor tests.

Prettify some ugly code in `spec/editor_spec.rb`.
This commit is contained in:
Kyrylo Silin 2013-01-14 06:55:35 +02:00 committed by John Mair
parent 9df47232cc
commit ae3f534b35
2 changed files with 23 additions and 8 deletions

View file

@ -1,3 +1,4 @@
require 'pathname'
require 'helper' require 'helper'
describe "edit" do describe "edit" do
@ -15,13 +16,25 @@ describe "edit" do
end end
describe "with FILE" do 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 it "should invoke Pry.config.editor with absolutified filenames" do
pry_eval 'edit lib/pry.rb' pry_eval 'edit lib/pry.rb'
@file.should == File.expand_path('lib/pry.rb') @file.should == File.expand_path('lib/pry.rb')
FileUtils.touch '/tmp/bar.rb' pry_eval "edit #@tf_path"
pry_eval 'edit /tmp/bar.rb' @file.should == @tf_path
@file.should == '/tmp/bar.rb'
end end
it "should guess the line number from a colon" do it "should guess the line number from a colon" do
@ -40,9 +53,11 @@ describe "edit" do
end end
it "works with files that contain blanks in their names" do it "works with files that contain blanks in their names" do
FileUtils.touch '/tmp/hello world.rb' tf_path = File.join(File.dirname(@tf_path), 'swoop and doop.rb')
pry_eval 'edit /tmp/hello world.rb' FileUtils.touch(tf_path)
@file.should == '/tmp/hello world.rb' pry_eval "edit #{ tf_path }"
@file.should == tf_path
FileUtils.rm(tf_path)
end end
describe do describe do

View file

@ -11,7 +11,7 @@ describe Pry::Editor do
# something "Temp". # something "Temp".
@tf_dir = Pathname.new(Dir::Tmpname.tmpdir) @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 end
unless Pry::Helpers::BaseHelpers.windows? unless Pry::Helpers::BaseHelpers.windows?
@ -68,7 +68,7 @@ describe Pry::Editor do
it 'should not shell-escape files' do it 'should not shell-escape files' do
Pry::Editor.invoke_editor(@tf_path, 10, true) Pry::Editor.invoke_editor(@tf_path, 10, true)
@file.should == "#@tf_path" @file.should == @tf_path
end end
end end
end end