From 24ab88a307ba74b6b82d33995519a08fe50b3821 Mon Sep 17 00:00:00 2001 From: Deepender Date: Wed, 11 Dec 2013 15:43:05 +0530 Subject: [PATCH] issue 998 test added --- Gemfile | 1 - lib/pry/method.rb | 2 +- spec/method_spec.rb | 15 ++++++++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 53000492..11553a13 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,6 @@ group :development do gem 'jist' gem 'rb-inotify', :require => 'false' gem 'rb-fsevent', :require => 'false' - gem 'debugger' end if RbConfig::CONFIG['ruby_install_name'] == 'rbx' diff --git a/lib/pry/method.rb b/lib/pry/method.rb index acb74469..f413a70d 100644 --- a/lib/pry/method.rb +++ b/lib/pry/method.rb @@ -64,7 +64,7 @@ class Pry from_obj(target.eval("self"), name, target) else from_str(name, target, :instance => true) or - from_str(name, target, :methods => true) + from_str(name, target, :methods => true) end rescue Pry::RescuableException diff --git a/spec/method_spec.rb b/spec/method_spec.rb index 86a32516..4ab97060 100644 --- a/spec/method_spec.rb +++ b/spec/method_spec.rb @@ -62,12 +62,25 @@ describe Pry::Method do meth.should == nil end - it 'should look up methods using klass.new.method syntax' do + it 'should look up methods using klass.new.method syntax' do klass = Class.new { def hello; :hello; end } meth = Pry::Method.from_str("klass.new.hello", Pry.binding_for(binding)) meth.name.should == "hello" end + it 'should take care of corner cases like mongo[] e.g Foo::Bar.new[]- issue 998' do + klass = Class.new { def []; :hello; end } + meth = Pry::Method.from_str("klass.new[]", Pry.binding_for(binding)) + meth.name.should == "[]" + end + + it 'should take care of cases like $ mongo[] - issue 998' do + f = Class.new { def []; :hello; end } + binding.eval("f = {}") + meth = Pry::Method.from_str("f[]", Pry.binding_for(binding)) + meth.name.should == "[]" + end + it 'should look up instance methods using klass.meth#method syntax' do klass = Class.new { def self.meth; Class.new; end } meth = Pry::Method.from_str("klass.meth#initialize", Pry.binding_for(binding))