Skip to content

Commit

Permalink
Fixed error raised when trying to wrap a non-existing object instance…
Browse files Browse the repository at this point in the history
… method
  • Loading branch information
Paul Engel committed May 2, 2011
1 parent ba04d9b commit b47b101
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rdoc
Expand Up @@ -5,6 +5,7 @@
* Improved object_instance.unextend
* Created a single point of definition for determination to whether or not unextend a certain module
* Added object.meta_class? (aliased with singleton_class?)
* Fixed error raised when trying to wrap a non-existing object instance method

== Version 0.1.1 (May 1, 2011)

Expand Down
2 changes: 1 addition & 1 deletion lib/unextendable/object.rb
Expand Up @@ -60,7 +60,7 @@ def wrap_unextendable_module(mod)
def wrap_unextendable_method(name)
return if meta_class.method_procs.key? name

meta_class.method_procs[name] = method(name).to_proc
meta_class.method_procs[name] = respond_to?(name) ? method(name).to_proc : nil

instance_eval <<-CODE
def #{name}(*args, &block)
Expand Down
13 changes: 11 additions & 2 deletions test/object_instance_test.rb
Expand Up @@ -77,6 +77,9 @@ module U
def name
"U"
end
def foo
"bar"
end
end
end

Expand All @@ -86,8 +89,14 @@ def name
end

should "call wrap_unextendable_method" do
@c.expects(:wrap_unextendable_method)
@c.expects(:wrap_unextendable_method).twice
@c.extend U
end

should "add nil value as method proc when not responding to module method name" do
@c.extend U
assert_equal 1, @c.meta_class.method_procs.select{|k, v| v.nil?}.size
assert_equal 1, @c.meta_class.method_procs.select{|k, v| v.class == Proc}.size
end

should "add the module to extended_modules" do
Expand All @@ -99,7 +108,7 @@ def name
should "add method proc to method_procs" do
assert @c.meta_class.send(:method_procs).empty?
@c.extend U
assert_equal 1, @c.meta_class.send(:method_procs).size
assert_equal 2, @c.meta_class.send(:method_procs).size
end

context "when calling an unextendable method" do
Expand Down

0 comments on commit b47b101

Please sign in to comment.