Skip to content

Instantly share code, notes, and snippets.

@macek
Forked from adamsanderson/test_mail_purge.rb
Created July 23, 2013 05:07

Revisions

  1. @adamsanderson adamsanderson revised this gist Dec 18, 2010. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions test_mail_purge.rb
    Original file line number Diff line number Diff line change
    @@ -39,9 +39,7 @@ def test_purging_mail
    mp = MailPurge.new(mock)
    mp.purge(date)

    mock.verify

    mock.verify
    assert mock.verify
    end

    end
  2. @adamsanderson adamsanderson created this gist Dec 18, 2010.
    47 changes: 47 additions & 0 deletions test_mail_purge.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    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)

    mock.verify

    mock.verify
    end

    end