Sha256: 339d9e64a4501110a56c1491464e7085f20e25800968c841f41774abfa693c2b

Contents?: true

Size: 1.64 KB

Versions: 30

Compression:

Stored size: 1.64 KB

Contents

require 'helper'

describe "Pry::DefaultCommands::Context" do
  describe "cd" do
    after do
      $obj = nil
    end

    it 'should cd into simple input' do
      b = Pry.binding_for(Object.new)
      b.eval("x = :mon_ouie")

      redirect_pry_io(InputTester.new("cd x", "$obj = self", "exit-all"), StringIO.new) do
        b.pry
      end

      $obj.should == :mon_ouie
    end

    it 'should break out of session with cd ..' do
      b = Pry.binding_for(:outer)
      b.eval("x = :inner")

      redirect_pry_io(InputTester.new("cd x", "$inner = self;", "cd ..", "$outer = self", "exit-all"), StringIO.new) do
        b.pry
      end
      $inner.should == :inner
      $outer.should == :outer
    end

    it 'should break out to outer-most session with cd /' do
      b = Pry.binding_for(:outer)
      b.eval("x = :inner")

      redirect_pry_io(InputTester.new("cd x", "$inner = self;", "cd 5", "$five = self", "cd /", "$outer = self", "exit-all"), StringIO.new) do
        b.pry
      end
      $inner.should == :inner
      $five.should == 5
      $outer.should == :outer
    end

    it 'should start a session on TOPLEVEL_BINDING with cd ::' do
      b = Pry.binding_for(:outer)

      redirect_pry_io(InputTester.new("cd ::", "$obj = self", "exit-all"), StringIO.new) do
        5.pry
      end
      $obj.should == TOPLEVEL_BINDING.eval('self')
    end

    it 'should cd into complex input (with spaces)' do
      o = Object.new
      def o.hello(x, y, z)
        :mon_ouie
      end

      redirect_pry_io(InputTester.new("cd hello 1, 2, 3", "$obj = self", "exit-all"), StringIO.new) do
        o.pry
      end
      $obj.should == :mon_ouie
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
pry-0.9.4pre1 test/test_default_commands/test_context.rb
pry-0.9.4pre1-i386-mswin32 test/test_default_commands/test_context.rb
pry-0.9.4pre1-i386-mingw32 test/test_default_commands/test_context.rb
pry-0.9.3 test/test_default_commands/test_context.rb
pry-0.9.3-i386-mswin32 test/test_default_commands/test_context.rb
pry-0.9.3-i386-mingw32 test/test_default_commands/test_context.rb
pry-0.9.3pre1 test/test_default_commands/test_context.rb
pry-0.9.3pre1-i386-mswin32 test/test_default_commands/test_context.rb
pry-0.9.3pre1-i386-mingw32 test/test_default_commands/test_context.rb
pry-0.9.2 test/test_default_commands/test_context.rb
pry-0.9.2-i386-mswin32 test/test_default_commands/test_context.rb
pry-0.9.2-i386-mingw32 test/test_default_commands/test_context.rb
pry-0.9.1 test/test_default_commands/test_context.rb
pry-0.9.1-i386-mswin32 test/test_default_commands/test_context.rb
pry-0.9.1-i386-mingw32 test/test_default_commands/test_context.rb
pry-0.9.0 test/test_default_commands/test_context.rb
pry-0.9.0-i386-mswin32 test/test_default_commands/test_context.rb
pry-0.9.0-i386-mingw32 test/test_default_commands/test_context.rb
pry-0.9.0pre3 test/test_default_commands/test_context.rb
pry-0.9.0pre3-i386-mswin32 test/test_default_commands/test_context.rb