From 6cd1d28d98a2fd3aa9c36b22ef0d3219f888af28 Mon Sep 17 00:00:00 2001 From: John Mair Date: Fri, 2 Sep 2011 22:25:18 +1200 Subject: [PATCH] merged in robgleeson's patch to pass pry instance to prompts, also added test_special_local.rb and test_shell.rb tests --- CHANGELOG | 1 + test/test_default_commands/test_shell.rb | 18 ++++++++++++ test/test_special_locals.rb | 35 ++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 test/test_default_commands/test_shell.rb create mode 100644 test/test_special_locals.rb diff --git a/CHANGELOG b/CHANGELOG index 939ea9c0..e93b7409 100644 --- a/CHANGELOG +++ b/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) diff --git a/test/test_default_commands/test_shell.rb b/test/test_default_commands/test_shell.rb new file mode 100644 index 00000000..bfbe0b43 --- /dev/null +++ b/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 diff --git a/test/test_special_locals.rb b/test/test_special_locals.rb new file mode 100644 index 00000000..4496a977 --- /dev/null +++ b/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