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

Use proper temp directories for each OS

Also, there was a failing test on Windows ("should shell-escape files").
You will see it if you're running tests on Windows. Make it conditional.
This commit is contained in:
Kyrylo Silin 2013-01-14 03:25:36 +02:00 committed by John Mair
parent d29f6b5c04
commit 9df47232cc

View file

@ -1,14 +1,31 @@
require 'pathname'
require 'helper' require 'helper'
describe Pry::Editor do
describe "build_editor_invocation_string" do
before do
class << Pry::Editor
public :build_editor_invocation_string
end
end
it 'should shell-escape files' do describe Pry::Editor do
Pry::Editor.build_editor_invocation_string("/tmp/hello world.rb", 5, true).should =~ %r(/tmp/hello\\ world.rb) class << Pry::Editor
public :build_editor_invocation_string
end
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 = @tf_dir.to_s + File::SEPARATOR + 'hello world.rb'
end
unless Pry::Helpers::BaseHelpers.windows?
describe "build_editor_invocation_string" do
before do
class << Pry::Editor
public :build_editor_invocation_string
end
end
it 'should shell-escape files' do
invocation_str = Pry::Editor.build_editor_invocation_string(@tf_path, 5, true)
invocation_str.should =~ /#@tf_dir.+hello\\ world\.rb/
end
end end
end end
@ -26,11 +43,13 @@ describe Pry::Editor do
end end
it "should replace / by \\" do it "should replace / by \\" do
Pry::Editor.build_editor_invocation_string("/tmp/hello world.rb", 5, true).should =~ %r(\\tmp\\) invocation_str = Pry::Editor.build_editor_invocation_string(@tf_path, 5, true)
invocation_str.should =~ %r(\\#{@tf_dir.basename}\\)
end end
it "should not shell-escape files" do it "should not shell-escape files" do
Pry::Editor.build_editor_invocation_string("/tmp/hello world.rb", 5, true).should =~ %r(hello world.rb) invocation_str = Pry::Editor.build_editor_invocation_string(@tf_path, 5, true)
invocation_str.should =~ /hello world\.rb/
end end
end end
@ -48,8 +67,8 @@ describe Pry::Editor do
end end
it 'should not shell-escape files' do it 'should not shell-escape files' do
Pry::Editor.invoke_editor('/tmp/hello world.rb', 10, true) Pry::Editor.invoke_editor(@tf_path, 10, true)
@file.should == "/tmp/hello world.rb" @file.should == "#@tf_path"
end end
end end
end end