diff --git a/lib/pry/helpers/module_introspection_helpers.rb b/lib/pry/helpers/module_introspection_helpers.rb index 96c374ba..7d11a07d 100644 --- a/lib/pry/helpers/module_introspection_helpers.rb +++ b/lib/pry/helpers/module_introspection_helpers.rb @@ -31,7 +31,7 @@ class Pry :method elsif Pry::WrappedModule.from_str(input, target) :module - elsif target.eval("defined? #{input} ") =~ /variable|constant/ + elsif target.eval("defined?(#{input})") =~ /variable|constant/ :variable_or_constant elsif find_command(input) :command diff --git a/test/test_default_commands/test_show_source.rb b/test/test_default_commands/test_show_source.rb index 37daeab3..5810b5ed 100644 --- a/test/test_default_commands/test_show_source.rb +++ b/test/test_default_commands/test_show_source.rb @@ -89,6 +89,11 @@ if !mri18_and_no_real_source_location? mock_pry(binding, "show-source c.new.method").should =~ /98/ end + it "should not show the source when a non-extant method is requested" do + c = Class.new{ def method; 98; end } + mock_pry(binding, "show-source c#wrongmethod").should =~ /could not be found/ + end + it "should find instance_methods even if the class has an override instance_method method" do c = Class.new{ def method;