spec/unit/imap/backup/account/folder_spec.rb in imap-backup-2.1.0 vs spec/unit/imap/backup/account/folder_spec.rb in imap-backup-2.1.1

- old
+ new

@@ -23,11 +23,11 @@ Net::IMAP::NoResponseError.new(missing_mailbox_response) end let(:responses) { [] } let(:append_response) { nil } - context "#uids" do + describe "#uids" do let(:uids) { [5678, 123] } before { allow(imap).to receive(:uid_search).and_return(uids) } it "lists available messages" do @@ -43,11 +43,11 @@ expect(subject.uids).to eq([]) end end end - context "#fetch" do + describe "#fetch" do let(:message_body) { instance_double(String, force_encoding: nil) } let(:attributes) { {"RFC822" => message_body, "other" => "xxx"} } let(:fetch_data_item) do instance_double(Net::IMAP::FetchData, attr: attributes) end @@ -56,42 +56,50 @@ it "returns the message" do expect(subject.fetch(123)).to eq(attributes) end - context "if the server responds with nothing" do + context "when the server responds with nothing" do before { allow(imap).to receive(:uid_fetch) { nil } } it "is nil" do expect(subject.fetch(123)).to be_nil end end - context "if the mailbox doesn't exist" do + context "when the mailbox doesn't exist" do before do allow(imap).to receive(:examine).and_raise(missing_mailbox_error) end it "is nil" do expect(subject.fetch(123)).to be_nil end end + context "when the response doesn't have RFC822" do + let(:attributes) { {} } + + it "is nil" do + expect(subject.fetch(123)).to be_nil + end + end + it "sets the encoding on the message" do subject.fetch(123) expect(message_body).to have_received(:force_encoding).with("utf-8") end end - context "#folder" do + describe "#folder" do it "is the name" do expect(subject.folder).to eq("my_folder") end end - context "#exist?" do + describe "#exist?" do context "when the folder exists" do it "is true" do expect(subject.exist?).to be_truthy end end @@ -105,11 +113,11 @@ expect(subject.exist?).to be_falsey end end end - context "#create" do + describe "#create" do context "when the folder exists" do before { subject.create } it "is does not create the folder" do expect(imap).to_not have_received(:create) @@ -126,11 +134,11 @@ expect(imap).to have_received(:create) end end end - context "#uid_validity" do + describe "#uid_validity" do let(:responses) { {"UIDVALIDITY" => ["x", "uid validity"]} } it "is returned" do expect(subject.uid_validity).to eq("uid validity") end @@ -146,18 +154,19 @@ end.to raise_error(Imap::Backup::FolderNotFound) end end end - context "#append" do + describe "#append" do let(:message) do instance_double( Email::Mboxrd::Message, imap_body: "imap body", - date: Time.now + date: message_date ) end + let(:message_date) { Time.new(2010, 10, 10, 9, 15, 22, 0) } let(:append_response) do OpenStruct.new(data: OpenStruct.new(code: OpenStruct.new(data: "1 2"))) end let(:result) { subject.append(message) } @@ -165,9 +174,14 @@ result end it "appends the message" do expect(imap).to have_received(:append) + end + + it "sets the date and time" do + expect(imap).to have_received(:append). + with(anything, anything, anything, message_date) end it "returns the new uid" do expect(result).to eq(2) end