From 5d983f49a23e0bf92095433afff7215e11205061 Mon Sep 17 00:00:00 2001 From: Kyrylo Silin Date: Wed, 11 Jul 2012 21:34:44 +0300 Subject: [PATCH] Use Pad instead of global variables in tests First of all, rewrite `test_cd.rb`, so instead of hard-coded so called "binding stack" and "old stack" strings with indices (`bs1`, `os2`, etc.) we use Enumerator that lazily creates these strings for us. Also, implement exactly the same Enumerator for the `test_command_integration.rb`, because we use there a lot of operations with binding stack. Next, replace all unwanted use of global variables in other unit tests with Pad. Signed-off-by: Kyrylo Silin --- test/test_command_integration.rb | 122 ++++++++---------- test/test_default_commands/test_cd.rb | 75 ++++++----- test/test_default_commands/test_context.rb | 60 +++++---- .../test_documentation.rb | 13 +- .../test_default_commands/test_show_source.rb | 42 +++--- test/test_pry.rb | 7 +- 6 files changed, 161 insertions(+), 158 deletions(-) diff --git a/test/test_command_integration.rb b/test/test_command_integration.rb index 0d773b0d..3bb56de1 100644 --- a/test/test_command_integration.rb +++ b/test/test_command_integration.rb @@ -3,6 +3,22 @@ require 'helper' describe "commands" do before do @str_output = StringIO.new + @o = Object.new + + # The `@bs` Enumerator yields strings for tests that require binding stack + # checkings (for example,Pad.bs1, Pad.bs2 and so on). + @bs = Enumerator.new do |y| + n = 0 + loop { y << "Pad.bs#{n+=1} = _pry_.binding_stack.dup" } + end + + @self = "Pad.self = self" + + Pad.bong = "bong" + end + + after do + Pad.clear end describe "alias_command" do @@ -118,78 +134,54 @@ describe "commands" do describe "Pry::Command#run" do it 'should allow running of commands with following whitespace' do - $_scratch = Object.new - o = Object.new - set = Pry::CommandSet.new do import Pry::Commands command "test-run" do run "cd / " end end - redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6/$_scratch", - "@nesting1 = _pry_.binding_stack.size", - "test-run", - "@obj = self", - "@nesting2 = _pry_.binding_stack.size", - "exit-all")) do - Pry.start(o, :commands => set) + redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6", @bs.next, "test-run", + @self, @bs.next, "exit-all")) do + Pry.start(@o, :commands => set) end - $_scratch.instance_variable_get(:@nesting1).should == 8 - o.instance_variable_get(:@obj).should == o - o.instance_variable_get(:@nesting2).should == 1 - $_scratch = nil + Pad.bs1.size.should == 7 + Pad.self.should == @o + Pad.bs2.size.should == 1 end it 'should allow running of cd command when contained in a single string' do - $_scratch = Object.new - o = Object.new - set = Pry::CommandSet.new do import Pry::Commands command "test-run" do run "cd /" end end - redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6/$_scratch", - "@nesting1 = _pry_.binding_stack.size", - "test-run", - "@obj = self", - "@nesting2 = _pry_.binding_stack.size", - "exit-all")) do - Pry.start(o, :commands => set) + redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6", @bs.next, "test-run", + @self, @bs.next, "exit-all")) do + Pry.start(@o, :commands => set) end - $_scratch.instance_variable_get(:@nesting1).should == 8 - o.instance_variable_get(:@obj).should == o - o.instance_variable_get(:@nesting2).should == 1 - $_scratch = nil + Pad.bs1.size.should == 7 + Pad.self.should == @o + Pad.bs2.size.should == 1 end it 'should allow running of cd command when split into array' do - $_scratch = Object.new - o = Object.new - set = Pry::CommandSet.new do import Pry::Commands command "test-run" do run "cd", "/" end end - redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6/$_scratch", - "@nesting1 = _pry_.binding_stack.size", - "test-run", - "@obj = self", - "@nesting2 = _pry_.binding_stack.size", - "exit-all")) do - Pry.start(o, :commands => set) + redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6", @bs.next, "test-run", + @self, @bs.next, "exit-all")) do + Pry.start(@o, :commands => set) end - $_scratch.instance_variable_get(:@nesting1).should == 8 - o.instance_variable_get(:@obj).should == o - o.instance_variable_get(:@nesting2).should == 1 - $_scratch = nil + Pad.bs1.size.should == 7 + Pad.self.should == @o + Pad.bs2.size.should == 1 end it 'should run a command from within a command' do @@ -273,16 +265,16 @@ describe "commands" do end it 'should interpolate ruby code into commands' do - klass = Pry::CommandSet.new do + set = Pry::CommandSet.new do command "hello", "", :keep_retval => true do |arg| arg end end - $test_interpolation = "bing" - Pry.new(:input => StringIO.new('hello #{$test_interpolation}'), :output => @str_output, :commands => klass).rep - @str_output.string.should =~ /bing/ - $test_interpolation = nil + str_input = StringIO.new('hello #{Pad.bong}') + Pry.new(:input => str_input, :output => @str_output, :commands => set).rep + + @str_output.string.should =~ /bong/ end # bug fix for https://github.com/pry/pry/issues/170 @@ -295,16 +287,16 @@ describe "commands" do end it 'should NOT interpolate ruby code into commands if :interpolate => false' do - klass = Pry::CommandSet.new do + set = Pry::CommandSet.new do command "hello", "", :keep_retval => true, :interpolate => false do |arg| arg end end - $test_interpolation = "bing" - Pry.new(:input => StringIO.new('hello #{$test_interpolation}'), :output => @str_output, :commands => klass).rep - @str_output.string.should =~ /test_interpolation/ - $test_interpolation = nil + str_input = StringIO.new('hello #{Pad.bong}') + Pry.new(:input => str_input, :output => @str_output, :commands => set).rep + + @str_output.string.should =~ /Pad\.bong/ end it 'should NOT try to interpolate pure ruby code (no commands) ' do @@ -315,12 +307,11 @@ describe "commands" do Pry.new(:input => StringIO.new('format #{aggy}'), :output => @str_output).rep @str_output.string.should.not =~ /NameError/ - $test_interpolation = "blah" @str_output = StringIO.new - Pry.new(:input => StringIO.new('format \'#{$test_interpolation}\''), :output => @str_output).rep + Pad.interp = "bong" + Pry.new(:input => StringIO.new('format \'#{Pad.interp}\''), :output => @str_output).rep - @str_output.string.should.not =~ /blah/ - $test_interpolation = nil + @str_output.string.should.not =~ /bong/ end it 'should create a command with a space in its name' do @@ -387,14 +378,11 @@ describe "commands" do end end - $obj = "bing" - redirect_pry_io(InputTester.new('hello #{$obj}'), @str_output) do + redirect_pry_io(InputTester.new('hello #{Pad.bong}'), @str_output) do Pry.new(:commands => set).rep end - @str_output.string.should =~ /hello bing/ - - $obj = nil + @str_output.string.should =~ /hello bong/ end it 'should create a regex command and arg_string should be interpolated' do @@ -404,16 +392,14 @@ describe "commands" do end end - $a1 = "bing" - $a2 = "bong" - $a3 = "bang" - redirect_pry_io(InputTester.new('hellojohn #{$a1} #{$a2} #{$a3}'), @str_output) do + Pad.bing = "bing" + Pad.bang = "bang" + redirect_pry_io(InputTester.new('hellojohn #{Pad.bing} #{Pad.bong} #{Pad.bang}'), + @str_output) do Pry.new(:commands => set).rep end @str_output.string.should =~ /hello john bing bong bang/ - - $a1 = $a2 = $a3 = nil end it 'if a regex capture is missing it should be nil' do @@ -430,7 +416,7 @@ describe "commands" do @str_output.string.should =~ /hello nil baby/ end - it 'should create a command in a nested context and that command should be accessible from the parent' do + it 'should create a command in a nested context and that command should be accessible from the parent' do x = "@x=nil\ncd 7\n_pry_.commands.instance_eval {\ncommand('bing') { |arg| run arg }\n}\ncd ..\nbing ls\nexit-all" redirect_pry_io(StringIO.new("@x=nil\ncd 7\n_pry_.commands.instance_eval {\ncommand('bing') { |arg| run arg }\n}\ncd ..\nbing ls\nexit-all"), @str_output) do Pry.new.repl(0) diff --git a/test/test_default_commands/test_cd.rb b/test/test_default_commands/test_cd.rb index def803ac..35a4e3f6 100644 --- a/test/test_default_commands/test_cd.rb +++ b/test/test_default_commands/test_cd.rb @@ -7,13 +7,18 @@ describe 'Pry::DefaultCommands::Cd' do @obj.instance_variable_set(:@y, 79) @o.instance_variable_set(:@obj, @obj) - # Shortcuts. They save a lot of typing. - @os1 = "Pad.os1 = _pry_.command_state['cd'].old_stack.dup" - @os2 = "Pad.os2 = _pry_.command_state['cd'].old_stack.dup" + # The `@bs` Enumerator yields strings for tests that require binding stack + # checkings (for example,Pad.bs1, Pad.bs2 and so on). + @bs = Enumerator.new do |y| + n = 0 + loop { y << "Pad.bs#{n+=1} = _pry_.binding_stack.dup" } + end - @bs1 = "Pad.bs1 = _pry_.binding_stack.dup" - @bs2 = "Pad.bs2 = _pry_.binding_stack.dup" - @bs3 = "Pad.bs3 = _pry_.binding_stack.dup" + # Same as `@bs`, but for command state's old stack. + @os = Enumerator.new do |y| + n = 0 + loop { y << "Pad.os#{n+=1} = _pry_.command_state['cd'].old_stack.dup" } + end @self = "Pad.self = self" @inner = "Pad.inner = self" @@ -26,7 +31,7 @@ describe 'Pry::DefaultCommands::Cd' do describe 'state' do it 'should not to be set up in fresh instance' do - redirect_pry_io(InputTester.new(@os1, "exit-all")) do + redirect_pry_io(InputTester.new(@os.next, "exit-all")) do Pry.start(@o) end @@ -37,7 +42,8 @@ describe 'Pry::DefaultCommands::Cd' do describe 'old stack toggling with `cd -`' do describe 'in fresh pry instance' do it 'should not toggle when there is no old stack' do - redirect_pry_io(InputTester.new("cd -", @bs1, "cd -", @bs2, "exit-all")) do + redirect_pry_io(InputTester.new("cd -", @bs.next, "cd -", + @bs.next, "exit-all")) do Pry.start(@o) end @@ -52,7 +58,7 @@ describe 'Pry::DefaultCommands::Cd' do end it 'should not toggle and should keep correct old stack' do - redirect_pry_io(InputTester.new("cd @", @os1, "cd -", @os2, "exit-all")) do + redirect_pry_io(InputTester.new("cd @", @os.next, "cd -", @os.next, "exit-all")) do Pry.start(@o) end @@ -61,7 +67,8 @@ describe 'Pry::DefaultCommands::Cd' do end it 'should not toggle and should keep correct current binding stack' do - redirect_pry_io(InputTester.new("cd @", @bs1, "cd -", @bs2, "exit-all")) do + redirect_pry_io(InputTester.new("cd @", @bs.next, "cd -", + @bs.next, "exit-all")) do Pry.start(@o) end @@ -72,8 +79,8 @@ describe 'Pry::DefaultCommands::Cd' do describe 'when using simple cd syntax' do it 'should toggle' do - redirect_pry_io(InputTester.new("cd :mon_dogg", "cd -", @bs1, - "cd -", @bs2, "exit-all")) do + redirect_pry_io(InputTester.new("cd :mon_dogg", "cd -", @bs.next, + "cd -", @bs.next, "exit-all")) do Pry.start(@o) end @@ -84,8 +91,8 @@ describe 'Pry::DefaultCommands::Cd' do describe "when using complex cd syntax" do it 'should toggle with a complex path (simple case)' do - redirect_pry_io(InputTester.new("cd 1/2/3", "cd -", @bs1, - "cd -", @bs2, "exit-all")) do + redirect_pry_io(InputTester.new("cd 1/2/3", "cd -", @bs.next, + "cd -", @bs.next, "exit-all")) do Pry.start(@o) end @@ -95,7 +102,7 @@ describe 'Pry::DefaultCommands::Cd' do it 'should toggle with a complex path (more complex case)' do redirect_pry_io(InputTester.new("cd 1/2/3", "cd ../4", "cd -", - @bs1, "cd -", @bs2, "exit-all")) do + @bs.next, "cd -", @bs.next, "exit-all")) do Pry.start(@o) end @@ -107,7 +114,7 @@ describe 'Pry::DefaultCommands::Cd' do describe 'series of cd calls' do it 'should toggle with fuzzy `cd -` calls' do redirect_pry_io(InputTester.new("cd :mon_dogg", "cd -", "cd 42", "cd -", - @bs1, "cd -", @bs2, "exit-all")) do + @bs.next, "cd -", @bs.next, "exit-all")) do Pry.start(@o) end @@ -118,8 +125,8 @@ describe 'Pry::DefaultCommands::Cd' do describe 'when using cd ..' do it 'should toggle with a simple path' do - redirect_pry_io(InputTester.new("cd :john_dogg", "cd ..", @bs1, - "cd -", @bs2, "exit-all")) do + redirect_pry_io(InputTester.new("cd :john_dogg", "cd ..", @bs.next, + "cd -", @bs.next, "exit-all")) do Pry.start(@o) end @@ -128,8 +135,8 @@ describe 'Pry::DefaultCommands::Cd' do end it 'should toggle with a complex path' do - redirect_pry_io(InputTester.new("cd 1/2/3/../4", "cd -", @bs1, - "cd -", @bs2, "exit-all")) do + redirect_pry_io(InputTester.new("cd 1/2/3/../4", "cd -", @bs.next, + "cd -", @bs.next, "exit-all")) do Pry.start(@o) end @@ -140,8 +147,8 @@ describe 'Pry::DefaultCommands::Cd' do describe 'when using cd ::' do it 'should toggle' do - redirect_pry_io(InputTester.new("cd ::", "cd -", @bs1, - "cd -", @bs2, "exit-all")) do + redirect_pry_io(InputTester.new("cd ::", "cd -", @bs.next, + "cd -", @bs.next, "exit-all")) do Pry.start(@o) end @@ -152,8 +159,8 @@ describe 'Pry::DefaultCommands::Cd' do describe 'when using cd /' do it 'should toggle' do - redirect_pry_io(InputTester.new("cd /", "cd -", @bs1, "cd :john_dogg", - "cd /", "cd -", @bs2, "exit-all")) do + redirect_pry_io(InputTester.new("cd /", "cd -", @bs.next, "cd :john_dogg", + "cd /", "cd -", @bs.next, "exit-all")) do Pry.start(@o) end @@ -169,8 +176,8 @@ describe 'Pry::DefaultCommands::Cd' do it 'should keep correct old binding' do redirect_pry_io(InputTester.new("cd :john_dogg", "cd :mon_dogg", - "cd :kyr_dogg", @control_d, @bs1, "cd -", - @bs2, "cd -", @bs3, "exit-all")) do + "cd :kyr_dogg", @control_d, @bs.next, + "cd -", @bs.next, "cd -", @bs.next, "exit-all")) do Pry.start(@o) end @@ -229,7 +236,7 @@ describe 'Pry::DefaultCommands::Cd' do end it 'should cd into an object and its ivar using cd obj/@ivar syntax' do - redirect_pry_io(InputTester.new("cd @obj/@x", @bs1, "exit-all")) do + redirect_pry_io(InputTester.new("cd @obj/@x", @bs.next, "exit-all")) do Pry.start(@o) end @@ -237,7 +244,7 @@ describe 'Pry::DefaultCommands::Cd' do end it 'should cd into an object and its ivar using cd obj/@ivar/ syntax (note following /)' do - redirect_pry_io(InputTester.new("cd @obj/@x/", @bs1, "exit-all")) do + redirect_pry_io(InputTester.new("cd @obj/@x/", @bs.next, "exit-all")) do Pry.start(@o) end @@ -246,7 +253,7 @@ describe 'Pry::DefaultCommands::Cd' do it 'should cd into previous object and its local using cd ../local syntax' do redirect_pry_io(InputTester.new("cd @obj", "local = :local", "cd @x", - "cd ../local", @bs1, "exit-all")) do + "cd ../local", @bs.next, "exit-all")) do Pry.start(@o) end @@ -254,7 +261,7 @@ describe 'Pry::DefaultCommands::Cd' do end it 'should cd into an object and its ivar and back again using cd obj/@ivar/.. syntax' do - redirect_pry_io(InputTester.new("cd @obj/@x/..", @bs1, "exit-all")) do + redirect_pry_io(InputTester.new("cd @obj/@x/..", @bs.next, "exit-all")) do Pry.start(@o) end @@ -262,7 +269,7 @@ describe 'Pry::DefaultCommands::Cd' do end it 'should cd into an object and its ivar and back and then into another ivar using cd obj/@ivar/../@y syntax' do - redirect_pry_io(InputTester.new("cd @obj/@x/../@y", @bs1, "exit-all")) do + redirect_pry_io(InputTester.new("cd @obj/@x/../@y", @bs.next, "exit-all")) do Pry.start(@o) end @@ -270,7 +277,8 @@ describe 'Pry::DefaultCommands::Cd' do end it 'should cd back to top-level and then into another ivar using cd /@ivar/ syntax' do - redirect_pry_io(InputTester.new("@z = 20", "cd @obj/@x/", "cd /@z", @bs1, "exit-all")) do + redirect_pry_io(InputTester.new("@z = 20", "cd @obj/@x/", "cd /@z", + @bs.next, "exit-all")) do Pry.start(@o) end @@ -298,7 +306,8 @@ describe 'Pry::DefaultCommands::Cd' do end it 'should not cd into complex input when it encounters an exception' do - redirect_pry_io(InputTester.new("cd 1/2/swoop_a_doop/3", @bs1, "exit-all")) do + redirect_pry_io(InputTester.new("cd 1/2/swoop_a_doop/3", + @bs.next, "exit-all")) do Pry.start(@o) end diff --git a/test/test_default_commands/test_context.rb b/test/test_default_commands/test_context.rb index 705d6c3b..57b77ca0 100644 --- a/test/test_default_commands/test_context.rb +++ b/test/test_default_commands/test_context.rb @@ -1,6 +1,17 @@ require 'helper' describe "Pry::DefaultCommands::Context" do + + before do + @self = "Pad.self = self" + @inner = "Pad.inner = self" + @outer = "Pad.outer = self" + end + + after do + Pad.clear + end + describe "exit-all" do it 'should break out of the repl loop of Pry instance and return nil' do redirect_pry_io(InputTester.new("exit-all")) do @@ -156,14 +167,13 @@ describe "Pry::DefaultCommands::Context" do describe "exit" do it 'should pop a binding with exit' do - b = Pry.binding_for(:outer) - b.eval("x = :inner") - - redirect_pry_io(InputTester.new("cd x", "$inner = self;", "exit", "$outer = self", "exit-all")) do - b.pry + redirect_pry_io(InputTester.new("cd :inner", @inner, "exit", + @outer, "exit-all")) do + Pry.start(:outer) end - $inner.should == :inner - $outer.should == :outer + + Pad.inner.should == :inner + Pad.outer.should == :outer end it 'should break out of the repl loop of Pry instance when binding_stack has only one binding with exit' do @@ -187,11 +197,11 @@ describe "Pry::DefaultCommands::Context" do end it 'should jump to the proper binding index in the stack' do - redirect_pry_io(InputTester.new("cd 1", "cd 2", "jump-to 1", "$blah = self", "exit-all")) do + redirect_pry_io(InputTester.new("cd 1", "cd 2", "jump-to 1", @self, "exit-all")) do Pry.start(0) end - $blah.should == 1 + Pad.self.should == 1 end it 'should print error when trying to jump to a non-existent binding index' do @@ -243,15 +253,13 @@ describe "Pry::DefaultCommands::Context" do end it "should eat the exception at the last new pry instance on raise-up" do - b = Pry.binding_for(:outer) - b.eval("x = :inner") - - redirect_pry_io(InputTester.new("x.pry", "raise NoMethodError", - "$inner = self", "raise-up NoMethodError", "$outer = self", "exit-all")) do - b.pry + redirect_pry_io(InputTester.new(":inner.pry", "raise NoMethodError", @inner, + "raise-up NoMethodError", @outer, "exit-all")) do + Pry.start(:outer) end - $inner.should == :inner - $outer.should == :outer + + Pad.inner.should == :inner + Pad.outer.should == :outer end it "should raise the most recently raised exception" do @@ -259,16 +267,16 @@ describe "Pry::DefaultCommands::Context" do end it "should allow you to cd up and (eventually) out" do - $deep = $inner = $outer = nil - b = Pry.binding_for(:outer) - b.eval("x = :inner") - redirect_pry_io(InputTester.new("cd x", "raise NoMethodError","$inner = self", - "deep = :deep", "cd deep","$deep = self","raise-up NoMethodError", "raise-up", "$outer = self", "raise-up", "exit-all")) do - lambda { b.pry }.should.raise NoMethodError + redirect_pry_io(InputTester.new("cd :inner", "raise NoMethodError", @inner, + "deep = :deep", "cd deep","Pad.deep = self", + "raise-up NoMethodError", "raise-up", @outer, + "raise-up", "exit-all")) do + lambda { Pry.start(:outer) }.should.raise NoMethodError end - $deep.should == :deep - $inner.should == :inner - $outer.should == :outer + + Pad.deep.should == :deep + Pad.inner.should == :inner + Pad.outer.should == :outer end end diff --git a/test/test_default_commands/test_documentation.rb b/test/test_default_commands/test_documentation.rb index ce06a303..efa72a55 100644 --- a/test/test_default_commands/test_documentation.rb +++ b/test/test_default_commands/test_documentation.rb @@ -5,6 +5,7 @@ if !mri18_and_no_real_source_location? describe "show-doc" do before do @str_output = StringIO.new + @o = Object.new end it 'should output a method\'s documentation' do @@ -32,17 +33,17 @@ if !mri18_and_no_real_source_location? end it 'should output a method\'s documentation if inside method without needing to use method name' do - o = Object.new + Pad.str_output = @str_output # sample comment - def o.sample - redirect_pry_io(InputTester.new("show-doc", "exit-all"), $out=StringIO.new) do + def @o.sample + redirect_pry_io(InputTester.new("show-doc", "exit-all"), Pad.str_output) do binding.pry end end - o.sample - $out.string.should =~ /sample comment/ - $out = nil + @o.sample + + Pad.str_output.string.should =~ /sample comment/ end it "should be able to find super methods" do diff --git a/test/test_default_commands/test_show_source.rb b/test/test_default_commands/test_show_source.rb index 49a9052e..c6b10d12 100644 --- a/test/test_default_commands/test_show_source.rb +++ b/test/test_default_commands/test_show_source.rb @@ -4,6 +4,11 @@ if !mri18_and_no_real_source_location? describe "show-source" do before do @str_output = StringIO.new + @o = Object.new + end + + after do + Pad.clear end it 'should output a method\'s source' do @@ -35,43 +40,39 @@ if !mri18_and_no_real_source_location? end it 'should output a method\'s source if inside method without needing to use method name' do - $str_output = StringIO.new + Pad.str_output = @str_output - o = Object.new - def o.sample - redirect_pry_io(InputTester.new("show-source", "exit-all"), $str_output) do + def @o.sample + redirect_pry_io(InputTester.new("show-source", "exit-all"), Pad.str_output) do binding.pry end end - o.sample + @o.sample - $str_output.string.should =~ /def o.sample/ - $str_output = nil + Pad.str_output.string.should =~ /def @o.sample/ end it 'should output a method\'s source if inside method without needing to use method name, and using the -l switch' do - $str_output = StringIO.new + Pad.str_output = @str_output - o = Object.new - def o.sample - redirect_pry_io(InputTester.new("show-source -l", "exit-all"), $str_output) do + def @o.sample + redirect_pry_io(InputTester.new("show-source -l", "exit-all"), Pad.str_output) do binding.pry end end - o.sample + @o.sample - $str_output.string.should =~ /\d+: def o.sample/ - $str_output = nil + Pad.str_output.string.should =~ /def @o.sample/ end it "should find methods even if there are spaces in the arguments" do - o = Object.new - def o.foo(*bars); + def @o.foo(*bars) "Mr flibble" - self; + self end - redirect_pry_io(InputTester.new("show-source o.foo('bar', 'baz bam').foo", "exit-all"), @str_output) do + redirect_pry_io(InputTester.new("show-source @o.foo('bar', 'baz bam').foo", + "exit-all"), @str_output) do binding.pry end @@ -146,10 +147,9 @@ if !mri18_and_no_real_source_location? end it "should not raise an exception when a non-extant super method is requested" do - o = Object.new - def o.foo(*bars); end + def @o.foo(*bars); end - mock_pry(binding, "show-source --super o.foo").should =~ /'self.foo' has no super method/ + mock_pry(binding, "show-source --super @o.foo").should =~ /'self.foo' has no super method/ end # dynamically defined method source retrieval is only supported in diff --git a/test/test_pry.rb b/test/test_pry.rb index 1550ca4e..7c9ab57f 100644 --- a/test/test_pry.rb +++ b/test/test_pry.rb @@ -59,12 +59,11 @@ describe Pry do if defined?(BasicObject) it 'should be able to operate inside the BasicObject class' do - $obj = nil - redirect_pry_io(InputTester.new(":foo", "$obj = _", "exit-all"), StringIO.new) do + redirect_pry_io(InputTester.new(":foo", "Pad.obj = _", "exit-all")) do BasicObject.pry end - $obj.should == :foo - $obj = nil + + Pad.obj.should == :foo end end