Sha256: 04f4f926b32fc26624fb74044efac0cf2d6242e54eea3071a07ab6fd42eb2910

Contents?: true

Size: 954 Bytes

Versions: 1

Compression:

Stored size: 954 Bytes

Contents

require "imap/backup/serializer/mbox_enumerator"

describe Imap::Backup::Serializer::MboxEnumerator do
  subject { described_class.new(mbox_pathname) }

  let(:mbox_pathname) { "/mbox/pathname" }
  let(:mbox_file) { instance_double(File) }
  let(:lines) { message1 + message2 + [nil] }
  let(:message1) do
    [
      "From Frida\r\n",
      "Hello\r\n"
    ]
  end
  let(:message2) do
    [
      "From John\r\n",
      "Hi\r\n"
    ]
  end

  before do
    allow(File).to receive(:open).and_call_original
    allow(File).to receive(:open).with(mbox_pathname).and_yield(mbox_file)
    allow(mbox_file).to receive(:gets).and_return(*lines)
  end

  describe "#each" do
    it "yields messages" do
      expect { |b| subject.each(&b) }.
        to yield_successive_args(message1.join, message2.join)
    end

    context "without a block" do
      it "returns an Enumerator" do
        expect(subject.each).to be_a(Enumerator)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
imap-backup-2.1.1 spec/unit/imap/backup/serializer/mbox_enumerator_spec.rb