diff --git a/test/helper.rb b/test/helper.rb index 631b944f..b40cefe0 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -250,7 +250,7 @@ end def pry_eval(*eval_strs) if eval_strs.first.is_a? String - binding = TOPLEVEL_BINDING + binding = Pry.toplevel_binding else binding = Pry.binding_for(eval_strs.shift) end diff --git a/test/test_code.rb b/test/test_code.rb index 8e89b2b9..31c928e2 100644 --- a/test/test_code.rb +++ b/test/test_code.rb @@ -7,7 +7,7 @@ describe Pry::Code do end should 'read lines from Pry\'s line buffer' do - mock_pry(':hay_guys') + pry_eval ':hay_guys' Pry::Code.from_file('(pry)').grep(/:hay_guys/).length.should == 1 end diff --git a/test/test_command.rb b/test/test_command.rb index ccbfe3d7..be7a97e7 100644 --- a/test/test_command.rb +++ b/test/test_command.rb @@ -616,12 +616,12 @@ describe "Pry::Command" do end it "should allow creating custom sub-classes of Pry::Command" do - mock_pry("my---test").should =~ /my-testmy-test/ + pry_eval("my---test").should =~ /my-testmy-test/ end if !mri18_and_no_real_source_location? it "should show the source of the process method" do - mock_pry("show-source my-test").should =~ /output.puts command_name/ + pry_eval("show-source my-test").should =~ /output.puts command_name/ end end end diff --git a/test/test_command_integration.rb b/test/test_command_integration.rb index 07b38850..5fba8c10 100644 --- a/test/test_command_integration.rb +++ b/test/test_command_integration.rb @@ -258,7 +258,10 @@ describe "commands" do end it 'should run a command in the context of a session' do - mock_pry("@session_ivar = 10", "_pry_.run_command('ls')").should =~ /@session_ivar/ + pry_tester.tap do |t| + t.eval "@session_ivar = 10", "_pry_.run_command('ls')" + t.last_output.should =~ /@session_ivar/ + end end end @@ -482,7 +485,6 @@ describe "commands" do @str_output.string.should =~ /6/ end - it 'a command (with :keep_retval => true) that replaces eval_string with a valid expression should overwrite the eval_string with the return value' do klass = Pry::CommandSet.new do command "hello", "", :keep_retval => true do diff --git a/test/test_pry.rb b/test/test_pry.rb index 9e949c31..a63f3c2c 100644 --- a/test/test_pry.rb +++ b/test/test_pry.rb @@ -253,24 +253,30 @@ describe Pry do describe "last_result" do it "should be set to the most recent value" do - mock_pry("2", "_ + 82").should =~ /84/ + pry_eval("2", "_ + 82").should == 84 end + # This test needs mock_pry because the command retvals work by + # replacing the eval_string, so _ won't be modified without Pry doing + # a REPL loop. it "should be set to the result of a command with :keep_retval" do - mock_pry("Pry::Commands.block_command '++', '', {:keep_retval => true} do |a| a.to_i + 1; end", '++ 86', '++ #{_}').should =~ /88/ + Pry::Commands.block_command '++', '', :keep_retval => true do |a| + a.to_i + 1 + end + + mock_pry('++ 86', '++ #{_}').should =~ /88/ end it "should be preserved over an empty line" do - mock_pry("2 + 2", " ", "\t", " ", "_ + 92").should =~ /96/ + pry_eval("2 + 2", " ", "\t", " ", "_ + 92").should == 96 end it "should be preserved when evalling a command without :keep_retval" do - mock_pry("2 + 2", "ls -l", "_ + 96").should =~ /100/ + pry_eval("2 + 2", "ls -l", "_ + 96").should == 100 end end describe "test loading rc files" do - before do Pry::HOME_RC_FILE.replace File.expand_path("../testrc", __FILE__) Pry::LOCAL_RC_FILE.replace File.expand_path("../testrc", __FILE__) + "/../testrc" diff --git a/test/test_pry_defaults.rb b/test/test_pry_defaults.rb index 17d0ebd2..503f65be 100644 --- a/test/test_pry_defaults.rb +++ b/test/test_pry_defaults.rb @@ -355,17 +355,17 @@ describe "test Pry defaults" do describe 'toplevel_binding' do it 'should be devoid of local variables' do - mock_pry(Pry.toplevel_binding, "ls -l").should.not =~ /version/ + pry_eval(Pry.toplevel_binding, "ls -l").should.not =~ /version/ end it 'should have self the same as TOPLEVEL_BINDING' do - mock_pry(Pry.toplevel_binding, "self.equal? TOPLEVEL_BINDING.eval('self')").should =~ /=> true/ + Pry.toplevel_binding.eval('self').should.equal? TOPLEVEL_BINDING.eval('self') end # https://github.com/rubinius/rubinius/issues/1779 unless Pry::Helpers::BaseHelpers.rbx? it 'should define private methods on Object' do - mock_pry(TOPLEVEL_BINDING, "def gooey_fooey; end") + TOPLEVEL_BINDING.eval 'def gooey_fooey; end' method(:gooey_fooey).owner.should == Object Pry::Method(method(:gooey_fooey)).visibility.should == :private end diff --git a/test/test_sticky_locals.rb b/test/test_sticky_locals.rb index 9166b511..b80881b9 100644 --- a/test/test_sticky_locals.rb +++ b/test/test_sticky_locals.rb @@ -2,23 +2,27 @@ require 'helper' describe "Sticky 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/ + proc { + pry_eval '_file_', '_dir_', '_ex_', '_pry_', '_' + }.should.not.raise(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/ + proc { + pry_eval 'cd 0', '_file_', '_dir_', '_ex_', '_pry_', '_' + }.should.not.raise(NameError) end - it 'locals should keep value after cd-ing(_pry_ and _ex_)' do - mock_pry("$x = _pry_;", "cd 0", "_pry_ == $x").should =~ /true/ + it 'locals should keep value after cd-ing (_pry_)' do + pry_tester.tap do |t| + pry = t.eval '_pry_' + t.eval 'cd 0' + t.eval('_pry_').should == pry + end + end + + # Using mock_pry here until we figure out exception handling + it 'locals should keep value after cd-ing (_ex_)' do mock_pry("error blah;", "$x = _ex_;", "cd 0", "_ex_ == $x").should =~ /true/ end @@ -27,8 +31,12 @@ describe "Sticky locals (_file_ and friends)" 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_eval('file-and-dir-test', 'cd 0', '_file_'). + should =~ /\/blah\/ostrich\.rb/ + + pry_eval('file-and-dir-test', 'cd 0', '_dir_'). + should =~ /\/blah/ + Pry.commands.delete "file-and-dir-test" end