Ruby: FibberMailman, mocking the Net::POP3.start
Lately I’m involved on projects that do a very intensive use of email accounts as input of information.
The use of mail in an automatic process is always a pain in the ass because of the huge casuistic and also for the difficulty to test it.
Nothing we can do with the first problem but for the second one here is my propose of a very simple Ruby Gem to mock the Net::POP3.start petition so you can simulate the emails that a real POP3 petition could find:
FibberMailman the mock for the Net::POP3.start.
Just charge a bunch of raw mails in an strings array and send them to the FibberMailman.lie_to_me method like this:
require 'fibber_mailman' raw_mails = [ File.read( "/fixtures/mail1.raw_mail" ) ), File.read( "/fixtures/mail2.raw_mail" ) ), ] FibberMailman.lie_to_me( raw_mails ) do <your code that uses the Net::POP3.start on any point> end
Every petition to the Net::POP3.start method into the inside block will be feed with fake emails built from the raw mail strings.