Peter Fitzgibbons
2010-Jun-11 18:22 UTC
[rspec-users] Rails 3 Mailer spec with arguments ?
This came out of the mailer generator w/ Rspec-rails installed : describe Notifier do it "should deliver activation instructions message" do @expected.subject = "Activation instructions" @expected.to = "to at example.org" @expected.from = "from at example.com" @expected.body = read_fixture("activation_instructions") end Could someone tell me how to modify this spec so that an argument can be sent into Notifier#activation_instructions ? class Notfier < ActionMailer::Base def activation_instructions(user) # ... mail :to => ... end end Thanks, -- Peter Fitzgibbons (847) 859-9550 peter.fitzgibbons at gmail.com IM GTalk: peter.fitzgibbons IM AOL: peter.fitzgibbons at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100611/9d85478b/attachment.html>
On Fri, Jun 11, 2010 at 2:22 PM, Peter Fitzgibbons <peter.fitzgibbons at gmail.com> wrote:> This came out of the mailer generator w/ Rspec-rails installed : > > describe Notifier do > ? it "should deliver activation instructions message" do > ??? @expected.subject = "Activation instructions" > ??? @expected.to????? = "to at example.org" > ??? @expected.from??? = "from at example.com" > ??? @expected.body??? = read_fixture("activation_instructions") > ? end > > > Could someone tell me how to modify this spec so that an argument can be > sent into Notifier#activation_instructions ? > > class Notfier < ActionMailer::Base > ??? def activation_instructions(user) > ??? ??? # ... mail :to => ... > ??? end > enduser = stub_model(User) @expected.activation_instructions(user) I''m adding a mailer() method to wrap @expected for the next release, but it''s the same object.
On Sat, Jun 12, 2010 at 7:01 AM, David Chelimsky <dchelimsky at gmail.com> wrote:> On Fri, Jun 11, 2010 at 2:22 PM, Peter Fitzgibbons > <peter.fitzgibbons at gmail.com> wrote: >> This came out of the mailer generator w/ Rspec-rails installed : >> >> describe Notifier do >> ? it "should deliver activation instructions message" do >> ??? @expected.subject = "Activation instructions" >> ??? @expected.to????? = "to at example.org" >> ??? @expected.from??? = "from at example.com" >> ??? @expected.body??? = read_fixture("activation_instructions") >> ? end >> >> >> Could someone tell me how to modify this spec so that an argument can be >> sent into Notifier#activation_instructions ? >> >> class Notfier < ActionMailer::Base >> ??? def activation_instructions(user) >> ??? ??? # ... mail :to => ... >> ??? end >> end > > user = stub_model(User) > @expected.activation_instructions(user) > > I''m adding a mailer() method to wrap @expected for the next release, > but it''s the same object.Disregard :) I''ll add a mailer method that access the mailer, and a message method that wraps @expected.
On Sat, Jun 12, 2010 at 7:04 AM, David Chelimsky <dchelimsky at gmail.com> wrote:> On Sat, Jun 12, 2010 at 7:01 AM, David Chelimsky <dchelimsky at gmail.com> wrote: >> On Fri, Jun 11, 2010 at 2:22 PM, Peter Fitzgibbons >> <peter.fitzgibbons at gmail.com> wrote: >>> This came out of the mailer generator w/ Rspec-rails installed : >>> >>> describe Notifier do >>> ? it "should deliver activation instructions message" do >>> ??? @expected.subject = "Activation instructions" >>> ??? @expected.to????? = "to at example.org" >>> ??? @expected.from??? = "from at example.com" >>> ??? @expected.body??? = read_fixture("activation_instructions") >>> ? end >>> >>> >>> Could someone tell me how to modify this spec so that an argument can be >>> sent into Notifier#activation_instructions ? >>> >>> class Notfier < ActionMailer::Base >>> ??? def activation_instructions(user) >>> ??? ??? # ... mail :to => ... >>> ??? end >>> end >> >> user = stub_model(User) >> @expected.activation_instructions(user) >> >> I''m adding a mailer() method to wrap @expected for the next release, >> but it''s the same object. > > Disregard :) > > I''ll add a mailer method that access the mailer, and a message method > that wraps @expected. >For now you can say: Notifier.__send__(:new).activation_instructions(user)
On Sat, Jun 12, 2010 at 7:18 AM, David Chelimsky <dchelimsky at gmail.com> wrote:> On Sat, Jun 12, 2010 at 7:04 AM, David Chelimsky <dchelimsky at gmail.com> wrote: >> On Sat, Jun 12, 2010 at 7:01 AM, David Chelimsky <dchelimsky at gmail.com> wrote: >>> On Fri, Jun 11, 2010 at 2:22 PM, Peter Fitzgibbons >>> <peter.fitzgibbons at gmail.com> wrote: >>>> This came out of the mailer generator w/ Rspec-rails installed : >>>> >>>> describe Notifier do >>>> ? it "should deliver activation instructions message" do >>>> ??? @expected.subject = "Activation instructions" >>>> ??? @expected.to????? = "to at example.org" >>>> ??? @expected.from??? = "from at example.com" >>>> ??? @expected.body??? = read_fixture("activation_instructions") >>>> ? end >>>> >>>> >>>> Could someone tell me how to modify this spec so that an argument can be >>>> sent into Notifier#activation_instructions ? >>>> >>>> class Notfier < ActionMailer::Base >>>> ??? def activation_instructions(user) >>>> ??? ??? # ... mail :to => ... >>>> ??? end >>>> end >>> >>> user = stub_model(User) >>> @expected.activation_instructions(user) >>> >>> I''m adding a mailer() method to wrap @expected for the next release, >>> but it''s the same object. >> >> Disregard :) >> >> I''ll add a mailer method that access the mailer, and a message method >> that wraps @expected. >> > > For now you can say: > > Notifier.__send__(:new).activation_instructions(user)OK - I got a patch into rails so rspec mailer specs can mix in behavior from an ActionMailer::TestCase::Behavior module. I updated mailer specs to use this and updated the generator to generate something more useful. Peter - is activation_instructions an action? If so you just need to say "Notifier.activation_instructions(user)" directly in the example. If it''s a helper method, I''d recommend moving it to a helper module and spec''ing it there. WDYT?