diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index 4626d69b..9ecf799f 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -424,7 +424,7 @@ class Pry # @param [String] eval_string The cumulative lines of input. # @param [Binding] target The target of the Pry session. # @return [Boolean] `true` if `val` is a command, `false` otherwise - def process_command(val, eval_string = '', target = TOPLEVEL_BINDING) + def process_command(val, eval_string = '', target = binding_stack.last) result = commands.process_line(val, { :target => target, :output => output, diff --git a/test/test_default_commands/test_context.rb b/test/test_default_commands/test_context.rb index 57b77ca0..fadc58af 100644 --- a/test/test_default_commands/test_context.rb +++ b/test/test_default_commands/test_context.rb @@ -1,8 +1,29 @@ require 'helper' -describe "Pry::DefaultCommands::Context" do +module ContextTestHelpers + def pry + @pry ||= Pry.new + end + def process_commands(*args) + args.flatten.each do |cmd| + pry.process_command cmd + end + end + + def evaluate_ruby(ruby) + pry.evaluate_ruby ruby + end + + def evaluate_self + pry.evaluate_ruby 'self' + end +end + +describe "Pry::DefaultCommands::Context" do before do + extend ContextTestHelpers + @self = "Pad.self = self" @inner = "Pad.inner = self" @outer = "Pad.outer = self" @@ -47,12 +68,17 @@ describe "Pry::DefaultCommands::Context" do class Cor def blimey! Cor.send :undef_method, :blimey! - # using [.] so the regex doesn't match itself - mock_pry(binding, 'whereami').should =~ /self[.]blimey!/ + Pad.binding = binding end end Cor.new.blimey! + + pry.binding_stack << Pad.binding + process_commands 'whereami' + + # using [.] so the regex doesn't match itself + # mock_pry(binding, 'whereami').should =~ /self[.]blimey!/ Object.remove_const(:Cor) end