test/object_test.rb in unextendable-0.1.6 vs test/object_test.rb in unextendable-0.1.7
- old
+ new
@@ -15,10 +15,14 @@
[title, name].reject{|x| x.nil? || x.empty?}.join " "
end
def name
"C"
end
+ private
+ def id
+ "C"
+ end
end
@c = C.new
@c.title = "Mr."
end
@@ -70,18 +74,30 @@
end
end
context "which are unextendable" do
setup do
+ module B
+ unextendable
+ public
+ def id
+ "B"
+ end
+ end
+
module U
unextendable
def name
"U"
end
def foo
"bar"
end
+ private
+ def id
+ "U"
+ end
end
end
should "respond to a non-extended instance method after extending" do
assert @c.respond_to?(:salutation)
@@ -93,18 +109,18 @@
@c.expects(:wrap_unextendable_module)
@c.extend A, U
end
should "call wrap_unextendable_method" do
- @c.expects(:wrap_unextendable_method).twice
+ @c.expects(:wrap_unextendable_method).times(3)
@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
+ assert_equal 2, @c.meta_class.method_procs.select{|k, v| v.class == Proc}.size
end
should "add the module to extended_modules" do
assert @c.meta_class.extended_modules.empty?
@c.extend U
@@ -112,11 +128,11 @@
end
should "add method proc to method_procs" do
assert @c.meta_class.send(:method_procs).empty?
@c.extend U
- assert_equal 2, @c.meta_class.send(:method_procs).size
+ assert_equal 3, @c.meta_class.send(:method_procs).size
end
context "when calling an unextendable method" do
should "call call_unextendable_method" do
@c.extend U
@@ -149,14 +165,27 @@
end
end
context "when unextending the module afterwards" do
should "remove the module from extended_modules" do
+ exception = assert_raises(NoMethodError) do
+ @c.id
+ end
+ assert_equal "private method `id' called for", exception.message[0..29]
+ assert_equal "C", @c.send(:id)
+
@c.extend U
assert @c.meta_class.extended_modules.include?(U)
+ assert_equal "private method `id' called for", exception.message[0..29]
+ assert_equal "U", @c.send(:id)
- @c.unextend U
+ @c.extend B
+ assert_equal "B", @c.send(:id)
+
+ @c.unextend
assert !@c.meta_class.extended_modules.include?(U)
+ assert_equal "private method `id' called for", exception.message[0..29]
+ assert_equal "C", @c.send(:id)
end
should "remove the module but when passed a block only when it passes" do
assert_equal "Mr. C", @c.salutation
\ No newline at end of file