require 'spec_helper' class A def foo end include MethodWatcher def foo2 end def foo3 end watch_methods :foo, :foo3 @overridden_methods = [] def self.overridden_methods @overridden_methods end def self.method_overriding method self.overridden_methods << method end end class B < A def foo3 end watch_methods def foo4 end def foo5 end unwatch_methods def foo end @overridden_methods = [] watch_methods :foo2 unwatch_methods :foo3, :foo5 def self.method_overriding method self.overridden_methods << method self.overridden_methods << :test end end class C < B (2..5).each do |i| define_method "foo#{i}".to_sym do end end end describe MethodWatcher do it 'should right!' do A.overridden_methods.should == [:foo3, :foo] B.overridden_methods.should == [:foo2, :test, :foo4, :test] end end