David Chelimsky
2007-Aug-30 04:47 UTC
[rspec-users] experimental rails story adapter in trunk
For those of you interested in getting a jump on learning about and using the new Story Runner in a Rails app, I''ve added an experimental Rails-Story adapter to trunk. You can see how to use it here: http://pastie.caboo.se/92320 This is PURELY EXPERIMENTAL, however it actually works and will likely not change much in the way that it does work. Happy hacking! David
I have a story where the user resets the password [hey, this story thing really rocks!]. It is expected that the password will change and that the user will be redirected to a login screen. A side effect is that the user will receive email with his/her new password. Where I''m stuck is in ascertaining whether mail was generated. Any thoughts on how this might be accomplished? Thanks ----------------- Story: Reset the Password As a registered user I want to be able to reset the password and have it emailed to me And then I want to log in Scenario: Reset password for an account Given A valid account is given: joe at schmoe.com When Resetting password for joe at schmoe.com Then Password state should change in database joe at schmoe.com And Registered user should be redirected to login screen And Email should be sent to the registered user And the new password should work :)
On 9/11/07, s.ross <cwdinfo at gmail.com> wrote:> > I have a story where the user resets the password [hey, this story > thing really rocks!]. It is expected that the password will change > and that the user will be redirected to a login screen. A side effect > is that the user will receive email with his/her new password. > > Where I''m stuck is in ascertaining whether mail was generated. > > Any thoughts on how this might be accomplished? > > Thanks > > ----------------- > > Story: Reset the Password > > As a registered user > I want to be able to reset the password and have it emailed to me > And then I want to log in > > > Scenario: Reset password for an account > > Given A valid account is given: joe at schmoe.com > > When Resetting password for joe at schmoe.com > > Then Password state should change in database joe at schmoe.com > And Registered user should be redirected to login screen > And Email should be sent to the registered user > And the new password should work :) > _______________________________________________Hi s.ross I know this was a while ago that you asked this question, but did you end up coming up with a solution? -Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071018/dd4cc475/attachment-0001.html
On Oct 18, 2007, at 6:09 AM, Daniel N wrote:> On 9/11/07, s.ross <cwdinfo at gmail.com> wrote: > I have a story where the user resets the password [hey, this story > thing really rocks!]. It is expected that the password will change > and that the user will be redirected to a login screen. A side effect > is that the user will receive email with his/her new password. > > Where I''m stuck is in ascertaining whether mail was generated. > > Any thoughts on how this might be accomplished? > > Thanks > > ----------------- > > Story: Reset the Password > > As a registered user > I want to be able to reset the password and have it emailed to me > And then I want to log in > > > Scenario: Reset password for an account > > Given A valid account is given: joe at schmoe.com > > When Resetting password for joe at schmoe.com > > Then Password state should change in database joe at schmoe.com > And Registered user should be redirected to login screen > And Email should be sent to the registered user > And the new password should work :) > _______________________________________________ > > Hi s.ross > > I know this was a while ago that you asked this question, but did > you end up coming up with a solution? > > -DanielNope, and embarrassingly, I took a different direction without preserving any traces of what I had been doing (can you say "frequent checkins?"). Ooops. Everything but verifying that the email was sent was running, but I never figured out how to verify that. --steve -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071019/f42cc1c3/attachment-0001.html
On 10/19/07, s.ross <cwdinfo at gmail.com> wrote:> > > > On Oct 18, 2007, at 6:09 AM, Daniel N wrote: > > > On 9/11/07, s.ross <cwdinfo at gmail.com> wrote: > > I have a story where the user resets the password [hey, this story > > thing really rocks!]. It is expected that the password will change > > and that the user will be redirected to a login screen. A side effect > > is that the user will receive email with his/her new password. > > > > Where I''m stuck is in ascertaining whether mail was generated. > > > > Any thoughts on how this might be accomplished? > > > > Thanks > > > > ----------------- > > > > Story: Reset the Password > > > > As a registered user > > I want to be able to reset the password and have it emailed to me > > And then I want to log in > > > > > > Scenario: Reset password for an account > > > > Given A valid account is given: joe at schmoe.com > > > > When Resetting password for joe at schmoe.com > > > > Then Password state should change in database joe at schmoe.com > > And Registered user should be redirected to login screen > > And Email should be sent to the registered user > > And the new password should work :) > > _______________________________________________ > > Hi s.ross > > I know this was a while ago that you asked this question, but did you end > up coming up with a solution? > > -Daniel > > Nope, and embarrassingly, I took a different direction without preserving > any traces of what I had been doing (can you say "frequent checkins?"). > Ooops. Everything but verifying that the email was sent was running, but I > never figured out how to verify that. > > --steve > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >I don''t have the agile book on hand, but in the chapter on testing they show how to test whether an email gets delivered. I imagine it would be the same thing. You set the mail delivery mechanism to test (which is done by default in environments/test.rb) and then check the test mail queue. See if that works. Pat
On Oct 19, 2007, at 1:54 PM, s.ross wrote:> On Oct 18, 2007, at 6:09 AM, Daniel N wrote: > >> On 9/11/07, s.ross <cwdinfo at gmail.com> wrote: >> I have a story where the user resets the password [hey, this story >> thing really rocks!]. It is expected that the password will change >> and that the user will be redirected to a login screen. A side effect >> is that the user will receive email with his/her new password. >> >> Where I''m stuck is in ascertaining whether mail was generated. >> >> Any thoughts on how this might be accomplished? >> >> Thanks >> >> ----------------- >> >> Story: Reset the Password >> >> As a registered user >> I want to be able to reset the password and have it emailed to me >> And then I want to log in >> >> >> Scenario: Reset password for an account >> >> Given A valid account is given: joe at schmoe.com >> >> When Resetting password for joe at schmoe.com >> >> Then Password state should change in database joe at schmoe.com >> And Registered user should be redirected to login screen >> And Email should be sent to the registered user >> And the new password should work :) >> _______________________________________________ >> >> Hi s.ross >> >> I know this was a while ago that you asked this question, but did >> you end up coming up with a solution? >> >> -Daniel > > Nope, and embarrassingly, I took a different direction without > preserving any traces of what I had been doing (can you say > "frequent checkins?"). Ooops. Everything but verifying that the > email was sent was running, but I never figured out how to verify > that. > > --steve > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-usersfrom my specs on restful_authentication''s models/user_observer_spec.rb context "A UserObserver" do setup do @user = mock(''user'') @user_observer = UserObserver.instance end specify "should call UserNotifier.deliver_signup_notification on user creation" do UserNotifier.should_receive(:deliver_signup_notification).with (@user) @user.stub!(:pending?).and_return(true) @user.stub!(:recently_activated?).and_return(false) @user.stub!(:recently_forgot_password?).and_return(false) @user_observer.after_save(@user) end (sorry its in pre-1.0 format) of course, this checks whether the email gets sent, not whether it got delivered... :) --linoj -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071019/b697d828/attachment.html
Yeah, you have two options really. The first is to do what linoj said and mock out the mailer that you are using. The other way, which Pat, was referring to was to actually check the mail queue. I generally do both. The reason being is that I want to make sure that I am using the correct mailer, AND that when I do use the correct mailer it actually renders the mail. So the latter option is more like doing controller testing with integration because the actual view for the email will be rendered based on what is passed into the mailer. I do this because I don''t usually spec out my mailers alone. I add the following to my spec_helper to make testing mail a little nicer: def mailer_setup ActionMailer::Base.delivery_method = :test ActionMailer::Base.perform_deliveries = true end def empty_the_mailer! ActionMailer::Base.deliveries=[] end def mailer_should_deliver(ammount_to_send=1) lambda { yield}.should change(ActionMailer::Base.deliveries, :size).by(ammount_to_send) end def last_email_sent ActionMailer::Base.deliveries.last end So in a spec you can say mailer_should_deliver 2 do @user.create! end or you can say stuff like last_email_sent.to.should == .... etc... -Ben Jonathan Linowes wrote:> > On Oct 19, 2007, at 1:54 PM, s.ross wrote: > >> On Oct 18, 2007, at 6:09 AM, Daniel N wrote: >> >>> On 9/11/07, *s.ross* <cwdinfo at gmail.com <mailto:cwdinfo at gmail.com>> >>> wrote: >>> >>> I have a story where the user resets the password [hey, this story >>> thing really rocks!]. It is expected that the password will change >>> and that the user will be redirected to a login screen. A side >>> effect >>> is that the user will receive email with his/her new password. >>> >>> Where I''m stuck is in ascertaining whether mail was generated. >>> >>> Any thoughts on how this might be accomplished? >>> >>> Thanks >>> >>> ----------------- >>> >>> Story: Reset the Password >>> >>> As a registered user >>> I want to be able to reset the password and have it emailed to me >>> And then I want to log in >>> >>> >>> Scenario: Reset password for an account >>> >>> Given A valid account is given: joe at schmoe.com >>> <mailto:joe at schmoe.com> >>> >>> When Resetting password for joe at schmoe.com >>> <mailto:joe at schmoe.com> >>> >>> Then Password state should change in database joe at schmoe.com >>> <mailto:joe at schmoe.com> >>> And Registered user should be redirected to login screen >>> And Email should be sent to the registered user >>> And the new password should work :) >>> _______________________________________________ >>> >>> >>> Hi s.ross >>> >>> I know this was a while ago that you asked this question, but did >>> you end up coming up with a solution? >>> >>> -Daniel >> >> Nope, and embarrassingly, I took a different direction without >> preserving any traces of what I had been doing (can you say "frequent >> checkins?"). Ooops. Everything but verifying that the email was sent >> was running, but I never figured out how to verify that. >> >> --steve >> >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org <mailto:rspec-users at rubyforge.org> >> http://rubyforge.org/mailman/listinfo/rspec-users > > from my specs on restful_authentication''s models/user_observer_spec.rb > > context "A UserObserver" do > setup do > @user = mock(''user'') > @user_observer = UserObserver.instance > end > > specify "should call UserNotifier.deliver_signup_notification on > user creation" do > UserNotifier.should_receive(:deliver_signup_notification).with(@user) > @user.stub!(:pending?).and_return(true) > @user.stub!(:recently_activated?).and_return(false) > @user.stub!(:recently_forgot_password?).and_return(false) > @user_observer.after_save(@user) > end > > (sorry its in pre-1.0 format) > > of course, this checks whether the email gets sent, not whether it got > delivered... :) > > --linoj > > ------------------------------------------------------------------------ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
On Oct 19, 2007, at 3:30 PM, Ben Mabey wrote:> <snip>yes, upon closer inspection, (as in http://www.vaporbase.com/postings/ Rspec_1.0_and_Restful_Authentication) in spec_helper.rb def set_mailer_in_test ActionMailer::Base.delivery_method = :test ActionMailer::Base.perform_deliveries = true ActionMailer::Base.deliveries = [] end and models/user_notifier_spec.rb : context "A UserNotifier on signup_notification" do setup do set_mailer_in_test @user = mock("user") @user.stub!(:email).and_return(''user at test.com'') @user.stub!(:activation_code).and_return(''code'') @user.stub!(:login).and_return(''user'') @user.stub!(:password).and_return(''password'') @user_notifier = UserNotifier.create_signup_notification(@user) end specify "should set @recipients to user''s email" do @user_notifier.to.should eql( ["user at test.com"] ) end specify "should set @subject to [YOURSITE] Please activate your new account" do @user_notifier.subject.should eql( "#{SITE_OPTIONS[''sitename'']}: Please activate your new account" ) end specify "should set @from to ADMINEMAIL" do @user_notifier.from.should eql( ["#{SITE_OPTIONS[''adminemail'']}"]) end specify "should contain login reminder (User: user) in mail body" do @user_notifier.body.should match( /Username: user/ ) end specify "should contain password reminder (Password: password) in mail body" do @user_notifier.body.should match( /Password: password/ ) end specify "should contain user activation url (http://YOURSITE/ activate/code) in mail body" do @user_notifier.body.should match( %r{http://#{SITE_OPTIONS [''sitedomain'']}/activate/code} ) end end
On Oct 19, 2007, at 12:21 PM, Jonathan Linowes wrote:> from my specs on restful_authentication''s models/user_observer_spec.rb > > context "A UserObserver" do > setup do > @user = mock(''user'') > @user_observer = UserObserver.instance > end > > specify "should call UserNotifier.deliver_signup_notification on > user creation" do > UserNotifier.should_receive(:deliver_signup_notification).with > (@user) > @user.stub!(:pending?).and_return(true) > @user.stub!(:recently_activated?).and_return(false) > @user.stub!(:recently_forgot_password?).and_return(false) > @user_observer.after_save(@user) > end > > (sorry its in pre-1.0 format)This is a great solution. I''ll give it a try. I know about checking the mail queue but wasn''t getting it done under the very first story runner. Again, I screwed up and didn''t check in my files so they vaporized. Acckkk! Fortunately, it was just a proof of concept sandbox for me to test using the story runner :) --steve