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)
if eval_strs.first.is_a? String
binding = TOPLEVEL_BINDING
binding = Pry.toplevel_binding
else
binding = Pry.binding_for(eval_strs.shift)
end

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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"

View file

@ -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

View file

@ -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