From: Sylvester Keil Date: 2011-12-12T04:13:23+09:00 Subject: Re: enforcing module contract with self.included? Try self.extended. For instance, the following code should print 'PASS' along with the error message: --- module AgeBasedApprovable def self.extended(base) unless base.respond_to?(:birthdate) raise 'Objects that extend AgeBasedApprovable must provide a birthdate method' end end end o = Object.new # monkey patch o for testing purposes def o.birthdate Time.now end # this should not raise an error o.extend(AgeBasedApprovable) o = Object.new begin o.extend(AgeBasedApprovable) puts 'FAIL' rescue => e puts 'PASS: ', e.message end --- On Dec 11, 2011, at 7:59 PM, Grary Stimon wrote: > Hey, > > What is the corresponding code in the AgeBasedApprovable module to beget > the behavior in the test below? If it is use of self.included, I've not > been able to get it to work... > > describe AgeBasedApprovable do > it "requires host object to provide a 'birthdate' method" do > host = Object.new > expect do > host.extend(AgeBasedApprovable) > end.to raise_error(/Objects that extend AgeBasedApprovable must > provide a 'birthdate' method/) > end > end > > Thanks, > > Grar > > -- > Posted via http://www.ruby-forum.com/. >