From d4de593f08706042a9c60756d079369cfa3726bc Mon Sep 17 00:00:00 2001 From: Jordon Bedwell Date: Thu, 5 Apr 2012 14:01:45 -0500 Subject: [PATCH] Partially fix #516 (see list of notes for more) * Move is_a? to == in pry_class.rb * Add test for __binding__ for @ConradIrwin. * Add regression test to prevent us from using is_a?(Binding). --- lib/pry/pry_class.rb | 2 +- test/test_default_commands/test_cd.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/test_default_commands/test_cd.rb diff --git a/lib/pry/pry_class.rb b/lib/pry/pry_class.rb index fd7b1e7f..e5a4599d 100644 --- a/lib/pry/pry_class.rb +++ b/lib/pry/pry_class.rb @@ -351,7 +351,7 @@ class Pry # @param [Object] target The object to get a `Binding` object for. # @return [Binding] The `Binding` object. def self.binding_for(target) - if target.is_a?(Binding) + if Binding === target target else if TOPLEVEL_BINDING.eval('self') == target diff --git a/test/test_default_commands/test_cd.rb b/test/test_default_commands/test_cd.rb new file mode 100644 index 00000000..c1774e7a --- /dev/null +++ b/test/test_default_commands/test_cd.rb @@ -0,0 +1,16 @@ +require 'helper' + +describe 'Pry::DefaultCommands::CD' do + describe 'cd' do + # Regression test for ticket #516. + #it 'should be able to cd into the Object BasicObject.' do + # mock_pry('cd BasicObject.new').should.not =~ /\Aundefined method `__binding__'/ + #end + + # Regression test for ticket #516 + # Possibly move higher up. + it 'should not fail with undefined BasicObject#is_a?' do + mock_pry('cd BasicObject.new').should.not =~ /undefined method `is_a\?'/ + end + end +end