[rspec-users] before_validation callbacks bypassed when stubbing :valid?

Edvard Majakari edvard at majakari.net
Wed Apr 16 09:10:10 EDT 2008

On Wed, Apr 16, 2008 at 2:54 PM, Ashley Moran
<ashley.moran at patchspace.co.uk> wrote:

>  Or equally, you could have a Factory class that knows how to create
>  valid objects.  This can be handy for generating test data, and
>  separates it from the class under test.  (Some metaprogramming would
>  let you define that in one class and still have it available as
>  MyModel.new_valid.)

Yep, that's better. This is very similar to what I just recently did:
I created a factory which creates
pure stub objects for all more complex models I needed in tests.
However, I mostly do just
fine having all the stubs/mocks in the spec file concerned; that's the
approach I like the most,
as then I have everything I need in a single file.
"One day, when he was naughty, Mr Bunnsy looked over the hedge into
Farmer Fred's field and it was full of fresh green lettuces. Mr
Bunnsy, however, was not full of lettuces. This did not seem fair."
 -- Terry Pratchett, Mr. Bunnsy Has An Adventure

More information about the rspec-users mailing list