2013-01-13 20:25:36 -05:00
|
|
|
require 'pathname'
|
2013-01-13 17:00:22 -05:00
|
|
|
require 'helper'
|
2013-01-13 20:25:36 -05:00
|
|
|
|
2013-01-13 17:00:22 -05:00
|
|
|
describe Pry::Editor do
|
2013-01-13 20:25:36 -05:00
|
|
|
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".
|
2013-01-14 05:11:37 -05:00
|
|
|
@tf_dir =
|
2013-01-14 11:43:19 -05:00
|
|
|
if Pry::Helpers::BaseHelpers.mri_19?
|
2013-01-14 05:11:37 -05:00
|
|
|
Pathname.new(Dir::Tmpname.tmpdir)
|
2013-01-14 11:43:19 -05:00
|
|
|
else
|
|
|
|
Pathname.new(Dir.tmpdir)
|
2013-01-14 05:11:37 -05:00
|
|
|
end
|
2013-01-13 20:25:36 -05:00
|
|
|
|
2013-01-13 23:55:35 -05:00
|
|
|
@tf_path = File.join(@tf_dir.to_s, 'hello world.rb')
|
2013-01-13 20:25:36 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
unless Pry::Helpers::BaseHelpers.windows?
|
|
|
|
describe "build_editor_invocation_string" do
|
|
|
|
before do
|
|
|
|
class << Pry::Editor
|
|
|
|
public :build_editor_invocation_string
|
|
|
|
end
|
2013-01-13 17:00:22 -05:00
|
|
|
end
|
|
|
|
|
2013-01-13 20:25:36 -05:00
|
|
|
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
|
2013-01-13 17:24:58 -05:00
|
|
|
end
|
2013-01-13 17:00:22 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "build_editor_invocation_string on windows" do
|
2013-01-13 17:24:58 -05:00
|
|
|
before do
|
|
|
|
class << Pry::Editor
|
|
|
|
def windows?; true; end
|
2013-01-13 17:00:22 -05:00
|
|
|
end
|
2013-01-13 17:24:58 -05:00
|
|
|
end
|
2013-01-13 17:00:22 -05:00
|
|
|
|
2013-01-13 17:24:58 -05:00
|
|
|
after do
|
|
|
|
class << Pry::Editor
|
|
|
|
undef windows?
|
2013-01-13 17:00:22 -05:00
|
|
|
end
|
2013-01-13 17:24:58 -05:00
|
|
|
end
|
2013-01-13 17:00:22 -05:00
|
|
|
|
2013-01-13 17:24:58 -05:00
|
|
|
it "should replace / by \\" do
|
2013-01-13 20:25:36 -05:00
|
|
|
invocation_str = Pry::Editor.build_editor_invocation_string(@tf_path, 5, true)
|
|
|
|
invocation_str.should =~ %r(\\#{@tf_dir.basename}\\)
|
2013-01-13 17:24:58 -05:00
|
|
|
end
|
2013-01-13 17:00:22 -05:00
|
|
|
|
2013-01-13 17:24:58 -05:00
|
|
|
it "should not shell-escape files" do
|
2013-01-13 20:25:36 -05:00
|
|
|
invocation_str = Pry::Editor.build_editor_invocation_string(@tf_path, 5, true)
|
|
|
|
invocation_str.should =~ /hello world\.rb/
|
2013-01-13 17:24:58 -05:00
|
|
|
end
|
2013-01-13 17:00:22 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'invoke_editor with a proc' do
|
2013-01-13 17:24:58 -05:00
|
|
|
before do
|
|
|
|
@old_editor = Pry.config.editor
|
2013-01-13 17:00:22 -05:00
|
|
|
Pry.config.editor = proc{ |file, line, blocking|
|
2013-01-13 17:24:58 -05:00
|
|
|
@file = file
|
|
|
|
nil
|
2013-01-13 17:00:22 -05:00
|
|
|
}
|
2013-01-13 17:24:58 -05:00
|
|
|
end
|
2013-01-13 17:00:22 -05:00
|
|
|
|
2013-01-13 17:24:58 -05:00
|
|
|
after do
|
|
|
|
Pry.config.editor = @old_editor
|
|
|
|
end
|
2013-01-13 17:00:22 -05:00
|
|
|
|
2013-01-13 17:24:58 -05:00
|
|
|
it 'should not shell-escape files' do
|
2013-01-13 20:25:36 -05:00
|
|
|
Pry::Editor.invoke_editor(@tf_path, 10, true)
|
2013-01-13 23:55:35 -05:00
|
|
|
@file.should == @tf_path
|
2013-01-13 17:24:58 -05:00
|
|
|
end
|
2013-01-13 17:00:22 -05:00
|
|
|
end
|
|
|
|
end
|