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

Pat Maddox pergesu at gmail.com
Tue Mar 13 14:58:07 EDT 2007


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


More information about the rspec-users mailing list