[Rspec-devel] tweak to arbitrary predicate support

David Astels dastels at daveastels.com
Wed Jul 19 19:01:12 EDT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Guys,

Here's a tweak to ShouldHelper.method_missing to look for (and use)  
pred as well as pred? when you say something like result.should.be.> 0

Here's my revised version of the method... I haven't committed it...  
there's probably a cleaner way to do it.

Dave


     def method_missing(sym, *args)
       message = default_message("should be #{sym}" + (args.empty? ?  
'' : (' ' + args.join(', '))))

       if @target.respond_to?("#{sym}?") then
         return if @target.send("#{sym}?", *args)
         fail_with_message(message)
       end

       if @target.respond_to?(sym) then
         return if @target.send(sym, *args)
         fail_with_message(message)
       end

       Kernel::raise(NoMethodError.new(sym, *args))
     end
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Darwin)

iD8DBQFEvrm4auez/L4x7g4RAjW+AJ4mzXPwY/f5qy6gHjX4z34uZUMt6wCgjI1n
aQNFBXXYfyFJcm2kjB4TL1c=
=0SR+
-----END PGP SIGNATURE-----


More information about the Rspec-devel mailing list