From 7f96d03e9a21698a387fbc10baa268362a9c9e1b Mon Sep 17 00:00:00 2001 From: John Mair Date: Mon, 23 May 2011 12:30:36 +1200 Subject: [PATCH] added tests for hist command, fixed tests for cd command, changed some method names in helpers.rb --- test/test_default_commands.rb | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/test/test_default_commands.rb b/test/test_default_commands.rb index ee7ed23c..f8616f01 100644 --- a/test/test_default_commands.rb +++ b/test/test_default_commands.rb @@ -2,6 +2,10 @@ require 'helper' describe "Pry::Commands" do + after do + $obj = nil + end + describe "hist" do before do Readline::HISTORY.clear @@ -122,35 +126,43 @@ describe "Pry::Commands" do b = Pry.binding_for(Object.new) b.eval("x = :mon_ouie") - redirect_pry_io(InputTester.new("cd x", "self.should == :mon_ouie;", "exit-all"), StringIO.new) do + redirect_pry_io(InputTester.new("cd x", "$obj = self", "exit-all"), StringIO.new) do Pry.new.repl(b) 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", "self.should == :inner;", "cd ..", "self.should == :outer", "exit-all"), StringIO.new) do + redirect_pry_io(InputTester.new("cd x", "$inner = self;", "cd ..", "$outer = self", "exit-all"), StringIO.new) do Pry.new.repl(b) 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", "self.should == :inner;", "cd 5", "self.should == 5", "cd /", "self.should == :outer", "exit-all"), StringIO.new) do + redirect_pry_io(InputTester.new("cd x", "$inner = self;", "cd 5", "$five = self", "cd /", "$outer = self", "exit-all"), StringIO.new) do Pry.new.repl(b) 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 ::", "self.should == TOPLEVEL_BINDING.eval('self')", "exit-all"), StringIO.new) do + redirect_pry_io(InputTester.new("cd ::", "$obj = self", "exit-all"), StringIO.new) do Pry.new.repl(5) end + $obj.should == TOPLEVEL_BINDING.eval('self') end it 'should cd into complex input (with spaces)' do @@ -159,9 +171,10 @@ describe "Pry::Commands" do :mon_ouie end - redirect_pry_io(InputTester.new("cd hello 1, 2, 3", "self.should == :mon_ouie", "exit-all"), StringIO.new) do + redirect_pry_io(InputTester.new("cd hello 1, 2, 3", "$obj = self", "exit-all"), StringIO.new) do Pry.new.repl(o) end + $obj.should == :mon_ouie end end end