pry--pry/spec/editor_spec.rb

53 lines
1.4 KiB
Ruby
Raw Normal View History

require 'pathname'
describe Pry::Editor do
2014-04-29 07:27:16 +00: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".
@tf_dir =
if Pry::Helpers::Platform.mri_19?
Pathname.new(Dir::Tmpname.tmpdir)
else
Pathname.new(Dir.tmpdir)
end
@tf_path = File.join(@tf_dir.to_s, 'hello world.rb')
2014-04-29 07:27:16 +00:00
@editor = Pry::Editor.new(Pry.new)
end
describe "build_editor_invocation_string", skip: !Pry::Helpers::Platform.windows? do
it 'should shell-escape files' do
invocation_str = @editor.build_editor_invocation_string(@tf_path, 5, true)
expect(invocation_str).to match(/#@tf_dir.+hello\\ world\.rb/)
2013-01-13 22:24:58 +00:00
end
end
describe "build_editor_invocation_string on windows" do
2013-01-13 22:24:58 +00:00
before do
allow(Pry::Helpers::Platform).to receive(:windows?).and_return(true)
2013-01-13 22:24:58 +00:00
end
2013-01-13 22:24:58 +00:00
it "should not shell-escape files" do
2014-04-29 07:27:16 +00:00
invocation_str = @editor.build_editor_invocation_string(@tf_path, 5, true)
2015-03-10 20:49:29 +00:00
expect(invocation_str).to match(/hello world\.rb/)
2013-01-13 22:24:58 +00:00
end
end
describe 'invoke_editor with a proc' do
2014-04-29 07:27:16 +00:00
it 'should not shell-escape files' do
editor = Pry::Editor.new(Pry.new(editor: proc { |file, _line, _blocking|
2013-01-13 22:24:58 +00:00
@file = file
nil
2014-04-29 07:27:16 +00:00
}))
2014-04-29 07:27:16 +00:00
editor.invoke_editor(@tf_path, 10, true)
2015-03-10 20:49:29 +00:00
expect(@file).to eq(@tf_path)
2013-01-13 22:24:58 +00:00
end
end
end