2013-01-13 22:00:22 +00:00
|
|
|
require 'helper'
|
|
|
|
describe Pry::Editor do
|
|
|
|
describe "build_editor_invocation_string" do
|
2013-01-13 22:24:58 +00:00
|
|
|
before do
|
|
|
|
class << Pry::Editor
|
|
|
|
public :build_editor_invocation_string
|
2013-01-13 22:00:22 +00:00
|
|
|
end
|
2013-01-13 22:24:58 +00:00
|
|
|
end
|
2013-01-13 22:00:22 +00:00
|
|
|
|
2013-01-13 22:24:58 +00:00
|
|
|
it 'should shell-escape files' do
|
|
|
|
Pry::Editor.build_editor_invocation_string("/tmp/hello world.rb", 5, true).should =~ %r(/tmp/hello\\ world.rb)
|
|
|
|
end
|
2013-01-13 22:00:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "build_editor_invocation_string on windows" do
|
2013-01-13 22:24:58 +00:00
|
|
|
before do
|
|
|
|
class << Pry::Editor
|
|
|
|
def windows?; true; end
|
2013-01-13 22:00:22 +00:00
|
|
|
end
|
2013-01-13 22:24:58 +00:00
|
|
|
end
|
2013-01-13 22:00:22 +00:00
|
|
|
|
2013-01-13 22:24:58 +00:00
|
|
|
after do
|
|
|
|
class << Pry::Editor
|
|
|
|
undef windows?
|
2013-01-13 22:00:22 +00:00
|
|
|
end
|
2013-01-13 22:24:58 +00:00
|
|
|
end
|
2013-01-13 22:00:22 +00:00
|
|
|
|
2013-01-13 22:24:58 +00:00
|
|
|
it "should replace / by \\" do
|
|
|
|
Pry::Editor.build_editor_invocation_string("/tmp/hello world.rb", 5, true).should =~ %r(\\tmp\\)
|
|
|
|
end
|
2013-01-13 22:00:22 +00:00
|
|
|
|
2013-01-13 22:24:58 +00:00
|
|
|
it "should not shell-escape files" do
|
|
|
|
Pry::Editor.build_editor_invocation_string("/tmp/hello world.rb", 5, true).should =~ %r(hello world.rb)
|
|
|
|
end
|
2013-01-13 22:00:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'invoke_editor with a proc' do
|
2013-01-13 22:24:58 +00:00
|
|
|
before do
|
|
|
|
@old_editor = Pry.config.editor
|
2013-01-13 22:00:22 +00:00
|
|
|
Pry.config.editor = proc{ |file, line, blocking|
|
2013-01-13 22:24:58 +00:00
|
|
|
@file = file
|
|
|
|
nil
|
2013-01-13 22:00:22 +00:00
|
|
|
}
|
2013-01-13 22:24:58 +00:00
|
|
|
end
|
2013-01-13 22:00:22 +00:00
|
|
|
|
2013-01-13 22:24:58 +00:00
|
|
|
after do
|
|
|
|
Pry.config.editor = @old_editor
|
|
|
|
end
|
2013-01-13 22:00:22 +00:00
|
|
|
|
2013-01-13 22:24:58 +00:00
|
|
|
it 'should not shell-escape files' do
|
|
|
|
Pry::Editor.invoke_editor('/tmp/hello world.rb', 10, true)
|
|
|
|
@file.should == "/tmp/hello world.rb"
|
|
|
|
end
|
2013-01-13 22:00:22 +00:00
|
|
|
end
|
|
|
|
end
|