1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Remove some unnecessary mock_prys

This commit is contained in:
Ryan Fitzgerald 2012-09-08 22:29:00 -07:00
parent 0e221391b0
commit 9b52d358ae
7 changed files with 44 additions and 28 deletions

View file

@ -250,7 +250,7 @@ end
def pry_eval(*eval_strs) def pry_eval(*eval_strs)
if eval_strs.first.is_a? String if eval_strs.first.is_a? String
binding = TOPLEVEL_BINDING binding = Pry.toplevel_binding
else else
binding = Pry.binding_for(eval_strs.shift) binding = Pry.binding_for(eval_strs.shift)
end end

View file

@ -7,7 +7,7 @@ describe Pry::Code do
end end
should 'read lines from Pry\'s line buffer' do 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 Pry::Code.from_file('(pry)').grep(/:hay_guys/).length.should == 1
end end

View file

@ -616,12 +616,12 @@ describe "Pry::Command" do
end end
it "should allow creating custom sub-classes of Pry::Command" do 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 end
if !mri18_and_no_real_source_location? if !mri18_and_no_real_source_location?
it "should show the source of the process method" do 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 end
end end

View file

@ -258,7 +258,10 @@ describe "commands" do
end end
it 'should run a command in the context of a session' do 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
end end
@ -482,7 +485,6 @@ describe "commands" do
@str_output.string.should =~ /6/ @str_output.string.should =~ /6/
end 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 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 klass = Pry::CommandSet.new do
command "hello", "", :keep_retval => true do command "hello", "", :keep_retval => true do

View file

@ -253,24 +253,30 @@ describe Pry do
describe "last_result" do describe "last_result" do
it "should be set to the most recent value" do it "should be set to the most recent value" do
mock_pry("2", "_ + 82").should =~ /84/ pry_eval("2", "_ + 82").should == 84
end 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 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 end
it "should be preserved over an empty line" do 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 end
it "should be preserved when evalling a command without :keep_retval" do 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
end end
describe "test loading rc files" do describe "test loading rc files" do
before do before do
Pry::HOME_RC_FILE.replace File.expand_path("../testrc", __FILE__) Pry::HOME_RC_FILE.replace File.expand_path("../testrc", __FILE__)
Pry::LOCAL_RC_FILE.replace File.expand_path("../testrc", __FILE__) + "/../testrc" Pry::LOCAL_RC_FILE.replace File.expand_path("../testrc", __FILE__) + "/../testrc"

View file

@ -355,17 +355,17 @@ describe "test Pry defaults" do
describe 'toplevel_binding' do describe 'toplevel_binding' do
it 'should be devoid of local variables' 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 end
it 'should have self the same as TOPLEVEL_BINDING' do 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 end
# https://github.com/rubinius/rubinius/issues/1779 # https://github.com/rubinius/rubinius/issues/1779
unless Pry::Helpers::BaseHelpers.rbx? unless Pry::Helpers::BaseHelpers.rbx?
it 'should define private methods on Object' do 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 method(:gooey_fooey).owner.should == Object
Pry::Method(method(:gooey_fooey)).visibility.should == :private Pry::Method(method(:gooey_fooey)).visibility.should == :private
end end

View file

@ -2,23 +2,27 @@ require 'helper'
describe "Sticky locals (_file_ and friends)" do describe "Sticky locals (_file_ and friends)" do
it 'locals should all exist upon initialization' do it 'locals should all exist upon initialization' do
mock_pry("_file_").should.not =~ /NameError/ proc {
mock_pry("_dir_").should.not =~ /NameError/ pry_eval '_file_', '_dir_', '_ex_', '_pry_', '_'
mock_pry("_ex_").should.not =~ /NameError/ }.should.not.raise(NameError)
mock_pry("_pry_").should.not =~ /NameError/
mock_pry("_").should.not =~ /NameError/
end end
it 'locals should still exist after cd-ing into a new context' do it 'locals should still exist after cd-ing into a new context' do
mock_pry("cd 0", "_file_").should.not =~ /NameError/ proc {
mock_pry("cd 0","_dir_").should.not =~ /NameError/ pry_eval 'cd 0', '_file_', '_dir_', '_ex_', '_pry_', '_'
mock_pry("cd 0","_ex_").should.not =~ /NameError/ }.should.not.raise(NameError)
mock_pry("cd 0","_pry_").should.not =~ /NameError/
mock_pry("cd 0","_").should.not =~ /NameError/
end end
it 'locals should keep value after cd-ing(_pry_ and _ex_)' do it 'locals should keep value after cd-ing (_pry_)' do
mock_pry("$x = _pry_;", "cd 0", "_pry_ == $x").should =~ /true/ 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/ mock_pry("error blah;", "$x = _ex_;", "cd 0", "_ex_ == $x").should =~ /true/
end end
@ -27,8 +31,12 @@ describe "Sticky locals (_file_ and friends)" do
set_file_and_dir_locals("/blah/ostrich.rb") set_file_and_dir_locals("/blah/ostrich.rb")
end end
mock_pry("file-and-dir-test", "cd 0", "_file_").should =~ /\/blah\/ostrich\.rb/ pry_eval('file-and-dir-test', 'cd 0', '_file_').
a = mock_pry("file-and-dir-test", "cd 0", "_dir_").should =~ /\/blah/ should =~ /\/blah\/ostrich\.rb/
pry_eval('file-and-dir-test', 'cd 0', '_dir_').
should =~ /\/blah/
Pry.commands.delete "file-and-dir-test" Pry.commands.delete "file-and-dir-test"
end end