3

I'm trying to write some specs for my application aimed to process and resend incoming emails. It's built with Mailman App. I didn't find any good examples on how to do that. What am I actually trying is to create email (with Mail gem) and process it with Mailman. But there is only option of using stding for testing.

So, are there any examples of specs written to test the mailman apps?

Davert
  • 314
  • 1
  • 5

1 Answers1

0

I think it is useful to extract as much as possible out of your Mailman::Application block and put it into your app somewhere. Then test that processing.

This Railscast (pro-only, sorry) has an example of "An Alternative to Routing" that is pretty good.

Basically instead of doing something like:

Mailman::Application.run do
  subject(/Update (\d+)/) do |ticket_id|
    ...

you just say:

Mailman::Application.run do
  default do
    MailProcessor.receive_mail(message)
  end
end

Then the MailProcessor class would handle reading the message and calling the right other functions in your app (depending on the message's subject, recipient, sender, etc.) I would then RSpec test the MailProcessor class for doing the right thing.

This is similar to how I approach testing rake tasks (put the functionality in a lib file that you test, and have the rake task just call the lib file.) Then you can be fairly certain that the functionality is being tested properly. If you were paranoid about the rake task, you can try an approach like: http://robots.thoughtbot.com/post/11957424161/test-rake-tasks-like-a-boss.

Anthony Panozzo
  • 3,274
  • 1
  • 24
  • 22