Created
December 18, 2010 04:35
-
-
Save adamsanderson/746155 to your computer and use it in GitHub Desktop.
An example of using MiniTest::Mock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'minitest/mock' | |
require 'minitest/unit' | |
require 'date' | |
MiniTest::Unit.autorun | |
class TestMailPurge < MiniTest::Unit::TestCase | |
class MailPurge | |
def initialize(imap) | |
@imap = imap | |
end | |
def purge(date) | |
formatted_date = date.strftime('%d-%b-%Y') | |
@imap.authenticate('LOGIN', 'user', 'password') | |
@imap.select('INBOX') | |
message_ids = @imap.search(["BEFORE #{formatted_date}"]) | |
@imap.store(message_ids, "+FLAGS", [:Deleted]) | |
end | |
end | |
def test_purging_mail | |
date = Date.new(2010,1,1) | |
formatted_date = '01-Jan-2010' | |
ids = [4,5,6] | |
mock = MiniTest::Mock.new | |
# mock expects: | |
# method return arguments | |
#------------------------------------------------------------- | |
mock.expect(:authenticate, nil, ['LOGIN', 'user', 'password']) | |
mock.expect(:select, nil, ['INBOX']) | |
mock.expect(:search, ids, [["BEFORE #{formatted_date}"]]) | |
mock.expect(:store, nil, [ids, "+FLAGS", [:Deleted]]) | |
mp = MailPurge.new(mock) | |
mp.purge(date) | |
assert mock.verify | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing this.