Jack Kinsella
2010-Nov-17 18:49 UTC
[rspec-users] How To Mock A Chain (specifically ActionMailerModel.method.deliver)
Hi, In Rails 3 you deliver a mail message with the ActionMailerModel.method.deliver syntax (e.g. Notifier.welcome_message.deliver). How do you test that this method is called in Rspec. I''m looking for an equivalent to "stub_chain" which has expectations. I''m testing that messages are sent on certain events in the object life cycle (e.g. that an email is sent when an Award is created). I know it''s possible to abstract welcome_message.deliver into a single method call, but this seems overly inconvenient for such a simple case. Anyone any ideas on how to solve this problem? Kind Regards, Jack Kinsella
David Chelimsky
2010-Nov-25 12:22 UTC
[rspec-users] How To Mock A Chain (specifically ActionMailerModel.method.deliver)
On Wed, Nov 17, 2010 at 12:49 PM, Jack Kinsella <jack.kinsella at gmail.com> wrote:> Hi, > > In Rails 3 you deliver a mail message with the > ActionMailerModel.method.deliver syntax (e.g. > Notifier.welcome_message.deliver). How do you test that this method is > called in Rspec. I''m looking for an equivalent to "stub_chain" which > has expectations. I''m testing that messages are sent on certain events > in the object life cycle (e.g. that an email is sent when an Award is > created). > > I know it''s possible to abstract welcome_message.deliver into a single > method call, but this seems overly inconvenient for such a simple > case. > > Anyone any ideas on how to solve this problem?See this thread: http://groups.google.com/group/rspec/browse_thread/thread/6b8394836d2390b0# Cheers, David> > Kind Regards, > > Jack Kinsella
Jack Kinsella
2010-Nov-29 16:52 UTC
[rspec-users] How To Mock A Chain (specifically ActionMailerModel.method.deliver)
Cheers, very insightful. I liked your point about ease of testing having an inherent value. On Nov 25, 12:22?pm, David Chelimsky <dchelim... at gmail.com> wrote:> On Wed, Nov 17, 2010 at 12:49 PM, Jack Kinsella <jack.kinse... at gmail.com> wrote: > > Hi, > > > In Rails 3 you deliver a mail message with the > > ActionMailerModel.method.deliver syntax (e.g. > > Notifier.welcome_message.deliver). How do you test that this method is > > called in Rspec. I''m looking for an equivalent to "stub_chain" which > > has expectations. I''m testing that messages are sent on certain events > > in the object life cycle (e.g. that an email is sent when an Award is > > created). > > > I know it''s possible to abstract welcome_message.deliver into a single > > method call, but this seems overly inconvenient for such a simple > > case. > > > Anyone any ideas on how to solve this problem? > > See this thread:http://groups.google.com/group/rspec/browse_thread/thread/6b8394836d2... > > Cheers, > David > > > > > Kind Regards, > > > Jack Kinsella > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users