[rspec-users] Opening the singleton class of mocked objects

Pat Maddox pergesu at gmail.com
Tue Mar 13 22:35:46 EDT 2007

On 3/13/07, Pat Maddox <pergesu at gmail.com> wrote:
> I wrote a plugin [1] a while ago that lets me do validations on a
> single AR instance.  Instead of defining validations in an AR class, I
> can define them on a AR instance's singleton class:
> class << @video
>   validates_presence_of :title
> end
> One of my specs mocks Video.find, and the above code is run on the
> mock object.  When I run the spec, I get the expected
> undefined method `validates_presence_of' for
> #<Class:#<Spec::Mocks::Mock:0x33772e4>>
> The code works though, I get the expected behavior.  I just don't know
> how to spec it.  Thoughts?
> Pat
> [1] http://evang.eli.st/blog/2007/1/20/instance-validations-plugin

btw the obvious way to do this would be to make my mock object a null
object, then just stub the valid? method (which is what I ultimately
call in that action).  I know that my instance validations work fine
from other tests, so I can get away with that.  However it's blowing
up because the singleton class can't just accept any method.


More information about the rspec-users mailing list