Sha256: e85b0fbbab9083fc428bee3f7a4762ca166225d3cd54cfb2ae6d73b2a342d41f

Contents?: true

Size: 1.86 KB

Versions: 79

Compression:

Stored size: 1.86 KB

Contents

require 'pathname'
require 'helper'

describe Pry::Editor do
  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::BaseHelpers.mri_19?
        Pathname.new(Dir::Tmpname.tmpdir)
      else
        Pathname.new(Dir.tmpdir)
      end

    @tf_path = File.join(@tf_dir.to_s, '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

  describe "build_editor_invocation_string on windows" do
    before do
      class << Pry::Editor
        def windows?; true; end
      end
    end

    after do
      class << Pry::Editor
        undef windows?
      end
    end

    it "should replace / by \\" do
      invocation_str = Pry::Editor.build_editor_invocation_string(@tf_path, 5, true)
      invocation_str.should =~ %r(\\#{@tf_dir.basename}\\)
    end

    it "should not shell-escape files" do
      invocation_str = Pry::Editor.build_editor_invocation_string(@tf_path, 5, true)
      invocation_str.should =~ /hello world\.rb/
    end
  end

  describe 'invoke_editor with a proc' do
    before do
      @old_editor = Pry.config.editor
      Pry.config.editor = proc{ |file, line, blocking|
        @file = file
        nil
      }
    end

    after do
      Pry.config.editor = @old_editor
    end

    it 'should not shell-escape files' do
      Pry::Editor.invoke_editor(@tf_path, 10, true)
      @file.should == @tf_path
    end
  end
end

Version data entries

79 entries across 79 versions & 5 rubygems

Version Path
asana2flowdock-1.0.0 vendor/bundle/ruby/1.9.1/gems/pry-0.9.12.6/spec/editor_spec.rb
pry-0.9.12.6 spec/editor_spec.rb
pry-0.9.12.6-i386-mswin32 spec/editor_spec.rb
pry-0.9.12.6-i386-mingw32 spec/editor_spec.rb
pry-0.9.12.6-java spec/editor_spec.rb
pry-0.9.12.5 spec/editor_spec.rb
pry-0.9.12.5-i386-mswin32 spec/editor_spec.rb
pry-0.9.12.5-i386-mingw32 spec/editor_spec.rb
pry-0.9.12.5-java spec/editor_spec.rb
pry-0.9.12.4 spec/editor_spec.rb
pry-0.9.12.4-i386-mswin32 spec/editor_spec.rb
pry-0.9.12.4-i386-mingw32 spec/editor_spec.rb
pry-0.9.12.4-java spec/editor_spec.rb
pry-0.9.12.3 spec/editor_spec.rb
pry-0.9.12.3-i386-mswin32 spec/editor_spec.rb
pry-0.9.12.3-i386-mingw32 spec/editor_spec.rb
pry-0.9.12.3-java spec/editor_spec.rb
torquebox-console-0.3.0 vendor/bundle/jruby/1.9/gems/pry-0.9.12-java/spec/editor_spec.rb
sshp-0.0.2 vendor/ruby/1.9.1/gems/pry-0.9.12.2/spec/editor_spec.rb
sshp-0.0.1 vendor/ruby/1.9.1/gems/pry-0.9.12.2/spec/editor_spec.rb