Archive for the ‘testing’ tag
Testing sending a delayed_job email with Cucumber
I recently implemented delayed_job into one of our applications. It was done because the application was dropping emails at the expense of user experience. We had about 120+ “Net::SMTPServerBusy” notifications and something had to be done about that.
We had about six places in our application where the email-spec gem came into play with a nicely:
Then “thebaker@bakedweb.net” should receive 1 ?email
After implementing delayed_job they changed to:
Then “thebaker@bakedweb.net” should receive 1 delayed email
The question is: How would I go about implementing the step? I came up with the following:
Then /^"([^\"]*)” should receive 1 delayed email$/ do |arg1|
Delayed::Job.last.name[0..15].should == ‘Notifier.deliver’
end
I know my implementation is dirty and brakes if we are sending the email from somewhere else, but Notifier and it only takes into account 1 email. The real reason for this post is to pick you mind on how to better implement the step. How would you go about it?
Update: Kotrin from #cucumber came up with a neat regex for the step and tells us that we could probably expand on it to pick up on args.
Then /^"([^\"]*)” should receive 1 delayed email$/ do |arg1|
Delayed::Job.last.name.should match(/^Notifier\.deliver/)
end
