Skip to content
Browse files

merged in robgleeson's patch to pass pry instance to prompts, also ad…

…ded test_special_local.rb and test_shell.rb tests
  • Loading branch information...
1 parent e97652f commit 6cd1d28d98a2fd3aa9c36b22ef0d3219f888af28 @banister banister committed Sep 2, 2011
Showing with 54 additions and 0 deletions.
  1. +1 −0 CHANGELOG
  2. +18 −0 test/test_default_commands/test_shell.rb
  3. +35 −0 test/test_special_locals.rb
View
1 CHANGELOG
@@ -20,6 +20,7 @@
* ^C no longer captured
* got rid of Pry.active_instance, Pry.last_exception and friends.
* also special locals now shared among bindings in a pry instance (i.e _ex_ (and friends) re-injected into new binding entered with 'cd')
+* added third parameter to prompts, the pry instance itself (_pry) see https://github.com/pry/pry/issues/233 for why it's important
*/7/2011 version 0.9.3
* cat --ex (cats 5 lines above and below line in file where exception was raised)
View
18 test/test_default_commands/test_shell.rb
@@ -0,0 +1,18 @@
+require 'helper'
+
+describe "Pry::DefaultCommands::Shell" do
+ describe "cat" do
+
+ # this doesnt work so well on rbx due to differences in backtrace
+ # so we currently skip rbx until we figure out a workaround
+ if !rbx?
+ it 'cat --ex should give warning when exception is raised in repl' do
+ mock_pry("this raises error", "cat --ex").should =~ /Cannot cat exceptions raised in REPL/
+ end
+
+ it 'cat --ex should correctly display code that generated exception' do
+ mock_pry("broken_method", "cat --ex").should =~ /this method is broken/
+ end
+ end
+ end
+end
View
35 test/test_special_locals.rb
@@ -0,0 +1,35 @@
+require 'helper'
+
+describe "Special locals (_file_ and friends)" do
+ it 'locals should all exist upon initialization' do
+ mock_pry("_file_").should.not =~ /NameError/
+ mock_pry("_dir_").should.not =~ /NameError/
+ mock_pry("_ex_").should.not =~ /NameError/
+ mock_pry("_pry_").should.not =~ /NameError/
+ mock_pry("_").should.not =~ /NameError/
+ end
+
+ it 'locals should still exist after cd-ing into a new context' do
+ mock_pry("cd 0", "_file_").should.not =~ /NameError/
+ mock_pry("cd 0","_dir_").should.not =~ /NameError/
+ mock_pry("cd 0","_ex_").should.not =~ /NameError/
+ mock_pry("cd 0","_pry_").should.not =~ /NameError/
+ mock_pry("cd 0","_").should.not =~ /NameError/
+ end
+
+ it 'locals should keep value after cd-ing(_pry_ and _ex_)' do
+ mock_pry("$x = _pry_;", "cd 0", "_pry_ == $x").should =~ /true/
+ mock_pry("error blah;", "$x = _ex_;", "cd 0", "_ex_ == $x").should =~ /true/
+ end
+
+ it 'locals should keep value after cd-ing (_file_ and _dir_)' do
+ Pry.commands.command "file-and-dir-test" do
+ set_file_and_dir_locals("/blah/ostrich.rb")
+ end
+
+ mock_pry("file-and-dir-test", "cd 0", "_file_").should =~ /\/blah\/ostrich\.rb/
+ a = mock_pry("file-and-dir-test", "cd 0", "_dir_").should =~ /\/blah/
+ Pry.commands.delete "file-and-dir-test"
+ end
+
+end

0 comments on commit 6cd1d28

Please sign in to comment.
Something went wrong with that request. Please try again.