From 91a249845e2570f2d93e143c1220f4e2b9ba2318 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Wed, 7 Dec 2011 22:26:04 -0800 Subject: [PATCH] Handle -m/-M correctly [Fixes #365] --- lib/pry/helpers/options_helpers.rb | 7 +++-- .../test_introspection.rb | 30 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/pry/helpers/options_helpers.rb b/lib/pry/helpers/options_helpers.rb index 69fbe48b..437e18bc 100644 --- a/lib/pry/helpers/options_helpers.rb +++ b/lib/pry/helpers/options_helpers.rb @@ -47,11 +47,14 @@ class Pry # Add the derived :method_object option to a used Slop instance. def process_method_object_options(args, opts) - opts[:instance] = opts['instance-methods'] if opts.present?(:methods) # TODO: de-hack when we upgrade Slop: https://github.com/injekt/slop/pull/30 opts.options[:super].force_argument_value opts.options[:super].count if opts.present?(:super) - get_method_or_raise(args.empty? ? nil : args.join(" "), @method_target, opts.to_hash(true)) + get_method_or_raise(args.empty? ? nil : args.join(" "), @method_target, + :super => opts[:super], + :instance => opts.present?(:'instance-methods') && !opts.present?(:'methods'), + :methods => opts.present?(:'methods') && !opts.present?(:'instance-methods') + ) end end end diff --git a/test/test_default_commands/test_introspection.rb b/test/test_default_commands/test_introspection.rb index 0086c242..556e01ae 100644 --- a/test/test_default_commands/test_introspection.rb +++ b/test/test_default_commands/test_introspection.rb @@ -316,6 +316,36 @@ describe "Pry::DefaultCommands::Introspection" do str_output.string.should =~ /Mr flibble/ end + it "should find instance methods with -M" do + c = Class.new{ def moo; "ve over!"; end } + mock_pry(binding, "cd c","show-method -M moo").should =~ /ve over/ + end + + it "should not find instance methods with -m" do + c = Class.new{ def moo; "ve over!"; end } + mock_pry(binding, "cd c", "show-method -m moo").should =~ /could not be found/ + end + + it "should find normal methods with -m" do + c = Class.new{ def self.moo; "ve over!"; end } + mock_pry(binding, "cd c", "show-method -m moo").should =~ /ve over/ + end + + it "should not find normal methods with -M" do + c = Class.new{ def self.moo; "ve over!"; end } + mock_pry(binding, "cd c", "show-method -M moo").should =~ /could not be found/ + end + + it "should find normal methods with no -M or -m" do + c = Class.new{ def self.moo; "ve over!"; end } + mock_pry(binding, "cd c", "show-method moo").should =~ /ve over/ + end + + it "should find instance methods with no -M or -m" do + c = Class.new{ def moo; "ve over!"; end } + mock_pry(binding, "cd c", "show-method moo").should =~ /ve over/ + end + it "should find super methods" do class Foo def foo(*bars)