[rspec-users] "Tricks" for testing after_create callback???

Rick DeNatale rick.denatale at gmail.com
Thu Dec 13 10:54:11 EST 2007

On 12/13/07, David Chelimsky <dchelimsky at gmail.com> wrote:
> On Dec 13, 2007 8:59 AM, Rick DeNatale <rick.denatale at gmail.com> wrote:
> > On 12/13/07, Daniel Tenner <daniel.ruby at tenner.org> wrote:
> > > Then I definitely think there's little point in specifying what
> > > "deliver_secret_santa" is called with. The chances that you'll get
> > > that wrong are extremely small, and even if you do it will be picked
> > > up instantly by your integration tests, and be very easy to fix.

> > Well IMHO, I think that it's important to spec both.  Even though the
> > callback is simple, it's a crucial design point, and I'm not unknown
> > to break such assumptions as code progresses.
> >
> >
> > It shouldn't be so hard to do either,  I just can't figure out now,
> > why rspec seems to be calling the create in my spec twice.
> This is a bit scary :(
> Rick - would you mind sticking this information, a bit filtered, into
> the tracker?

Well, as I was doing just that, I looked a bit closer at those
walkbacks, and it occurred to me that I was assuming that rspec was
calling the method twice.

As it turns out, it was actually ActiveRecord calling the callback
twice, and it went away when I changed from

after_create do |msg|


def after_create

So I guess I need to follow up on Rails core!  Although that change
fixed things for this case.

And it just goes to show that it was important to spec this, since it
would be a bad thing (tm) if the email got sent twice.

Rick DeNatale

My blog on Ruby

More information about the rspec-users mailing list