Hi,

On Thu, Jan 27, 2011 at 21:48, Michael Guterl <mgut...@gmail.com> wrote:
> RSpec::Matchers.define :deliver do |message|
>  chain :with do |*args|
>    @with = args
>  end
>
>  match do |mailer|
>    mail = double
>    mail.should_receive(:deliver)
>
>    mailer.should_receive(message).with(*@with).and_return(mail)
>  end
> end
>
> Mailer.should deliver(:job_application).with(@job.id, @user.id)

On a recent Rails 3 project we implemented a matcher for sending email
but without using any stubs. It looks something like this:

  RSpec::Matchers.define :send_mail do
    match do |block|
      ActionMailer::Base.deliveries = []
      block.call
      ActionMailer::Base.deliveries.count.should == 1
      mail = ActionMailer::Base.deliveries.last
      # now inspect the mail object as you see fit
    end
  end

Then in our spec we have:

  expect { some_func }.to send_email

We also have chains for recipients, subject, content, and so on.

HTH,
Mike
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to