Sha256: 183d502e287f98ba6e5a2f185b9fbda9263a36dd06227fbcfd94950fc442428c

Contents?: true

Size: 1.05 KB

Versions: 6

Compression:

Stored size: 1.05 KB

Contents

require 'spec_helper'

describe MailRoom::MailboxHandler do
  describe 'process mailbox' do
    let(:imap) {stub}
    let(:mailbox) {MailRoom::Mailbox.new}

    it 'fetches and delivers all new messages from ids' do
      imap.stubs(:search).returns([1,2])
      imap.stubs(:fetch).returns(['message1', 'message2'])
      mailbox.stubs(:deliver)

      handler = MailRoom::MailboxHandler.new(mailbox, imap)
      handler.process

      imap.should have_received(:search).with('UNSEEN')
      imap.should have_received(:fetch).with([1,2], 'RFC822')
      mailbox.should have_received(:deliver).with('message1')
      mailbox.should have_received(:deliver).with('message2')
    end

    it 'returns no messages if there are no ids' do
      imap.stubs(:search).returns([])
      imap.stubs(:fetch)
      mailbox.stubs(:deliver)

      handler = MailRoom::MailboxHandler.new(mailbox, imap)
      handler.process

      imap.should have_received(:search).with('UNSEEN')
      imap.should have_received(:fetch).never
      mailbox.should have_received(:deliver).never
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mail_room-0.3.1 spec/lib/mailbox_handler_spec.rb
mail_room-0.3.0 spec/lib/mailbox_handler_spec.rb
mail_room-0.2.0 spec/lib/mailbox_handler_spec.rb
mail_room-0.1.0 spec/lib/mailbox_handler_spec.rb
mail_room-0.0.3 spec/lib/mailbox_handler_spec.rb
mail_room-0.0.2 spec/lib/mailbox_handler_spec.rb