Hi there, I''m trying to write a spec for and existing model. It has an after_create callback which I''d like to stub out. Any quick solution to this? Many thanks Rob Lacey
On Thu, Aug 14, 2008 at 9:53 AM, Rob Lacey <robl at mail.pigdestroyer.co.uk> wrote:> Hi there, > > I''m trying to write a spec for and existing model. It has an after_create > callback which I''d like to stub out. Any quick solution to this? >My first question is why do you want to stub it out? My second question is what spec are you wanting to stub it out in? -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com
Don''t stub out callbacks, rather spec the behavior of the model, which might mean stubbing out methods (in a different model?) called by the callback. On Aug 14, 2008, at 9:53 AM, Rob Lacey wrote:> Hi there, > > I''m trying to write a spec for and existing model. It has an > after_create callback which I''d like to stub out. Any quick > solution to this? > > Many thanks > > Rob Lacey > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Rob Lacey wrote:> Hi there, > > I''m trying to write a spec for and existing model. It has an > after_create callback which I''d like to stub out. Any quick solution > to this? > > Many thanks > > Rob Lacey > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-usersWhat you may want to do is move the after_create into an observer and then disconnect your observers during most of your specs. You can do this with Pat Maddox''s plugin: http://evang.eli.st/blog/2007/11/22/better-rails-testing-decoupling-observers http://github.com/pat-maddox/no-peeping-toms/tree/master -Ben