2013-01-14 03:25:36 +02:00
|
|
|
require 'pathname'
|
2014-03-14 05:31:24 +01:00
|
|
|
require_relative 'helper'
|
2013-01-14 03:25:36 +02:00
|
|
|
|
2013-01-13 14:00:22 -08:00
|
|
|
describe Pry::Editor do
|
2014-04-29 00:27:16 -07:00
|
|
|
class Pry::Editor
|
2013-01-14 03:25:36 +02:00
|
|
|
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 12:11:37 +02:00
|
|
|
@tf_dir =
|
2013-01-14 18:43:19 +02:00
|
|
|
if Pry::Helpers::BaseHelpers.mri_19?
|
2013-01-14 12:11:37 +02:00
|
|
|
Pathname.new(Dir::Tmpname.tmpdir)
|
2013-01-14 18:43:19 +02:00
|
|
|
else
|
|
|
|
Pathname.new(Dir.tmpdir)
|
2013-01-14 12:11:37 +02:00
|
|
|
end
|
2013-01-14 03:25:36 +02:00
|
|
|
|
2013-01-14 06:55:35 +02:00
|
|
|
@tf_path = File.join(@tf_dir.to_s, 'hello world.rb')
|
2014-04-29 00:27:16 -07:00
|
|
|
|
|
|
|
@editor = Pry::Editor.new(Pry.new)
|
2013-01-14 03:25:36 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
unless Pry::Helpers::BaseHelpers.windows?
|
|
|
|
describe "build_editor_invocation_string" do
|
|
|
|
it 'should shell-escape files' do
|
2014-04-29 00:27:16 -07:00
|
|
|
invocation_str = @editor.build_editor_invocation_string(@tf_path, 5, true)
|
2015-03-10 22:49:29 +02:00
|
|
|
expect(invocation_str).to match(/#@tf_dir.+hello\\ world\.rb/)
|
2013-01-14 03:25:36 +02:00
|
|
|
end
|
2013-01-13 14:24:58 -08:00
|
|
|
end
|
2013-01-13 14:00:22 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "build_editor_invocation_string on windows" do
|
2013-01-13 14:24:58 -08:00
|
|
|
before do
|
2014-04-29 00:27:16 -07:00
|
|
|
class Pry::Editor
|
2013-01-13 14:24:58 -08:00
|
|
|
def windows?; true; end
|
2013-01-13 14:00:22 -08:00
|
|
|
end
|
2013-01-13 14:24:58 -08:00
|
|
|
end
|
2013-01-13 14:00:22 -08:00
|
|
|
|
2013-01-13 14:24:58 -08:00
|
|
|
after do
|
2014-04-29 00:27:16 -07:00
|
|
|
class Pry::Editor
|
2013-01-13 14:24:58 -08:00
|
|
|
undef windows?
|
2013-01-13 14:00:22 -08:00
|
|
|
end
|
2013-01-13 14:24:58 -08:00
|
|
|
end
|
2013-01-13 14:00:22 -08:00
|
|
|
|
2013-01-13 14:24:58 -08:00
|
|
|
it "should not shell-escape files" do
|
2014-04-29 00:27:16 -07:00
|
|
|
invocation_str = @editor.build_editor_invocation_string(@tf_path, 5, true)
|
2015-03-10 22:49:29 +02:00
|
|
|
expect(invocation_str).to match(/hello world\.rb/)
|
2013-01-13 14:24:58 -08:00
|
|
|
end
|
2013-01-13 14:00:22 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'invoke_editor with a proc' do
|
2014-04-29 00:27:16 -07:00
|
|
|
it 'should not shell-escape files' do
|
|
|
|
editor = Pry::Editor.new(Pry.new(editor: proc{ |file, line, blocking|
|
2013-01-13 14:24:58 -08:00
|
|
|
@file = file
|
|
|
|
nil
|
2014-04-29 00:27:16 -07:00
|
|
|
}))
|
2013-01-13 14:00:22 -08:00
|
|
|
|
2014-04-29 00:27:16 -07:00
|
|
|
editor.invoke_editor(@tf_path, 10, true)
|
2015-03-10 22:49:29 +02:00
|
|
|
expect(@file).to eq(@tf_path)
|
2013-01-13 14:24:58 -08:00
|
|
|
end
|
2013-01-13 14:00:22 -08:00
|
|
|
end
|
|
|
|
end
|