spec/unit/imap/backup/account/folder_spec.rb in imap-backup-2.0.0 vs spec/unit/imap/backup/account/folder_spec.rb in imap-backup-2.1.0
- old
+ new
@@ -1,32 +1,32 @@
-require "spec_helper"
+# rubocop:disable RSpec/PredicateMatcher
describe Imap::Backup::Account::Folder do
+ subject { described_class.new(connection, "my_folder") }
+
let(:imap) do
instance_double(
Net::IMAP,
append: append_response,
create: nil,
examine: nil,
responses: responses
)
end
- let(:connection) { double("Imap::Backup::Account::Connection", imap: imap) }
+ let(:connection) do
+ instance_double(Imap::Backup::Account::Connection, imap: imap)
+ end
let(:missing_mailbox_data) do
- double("Data", text: "Unknown Mailbox: my_folder")
+ OpenStruct.new(text: "Unknown Mailbox: my_folder")
end
- let(:missing_mailbox_response) do
- double("Response", data: missing_mailbox_data)
- end
+ let(:missing_mailbox_response) { OpenStruct.new(data: missing_mailbox_data) }
let(:missing_mailbox_error) do
Net::IMAP::NoResponseError.new(missing_mailbox_response)
end
let(:responses) { [] }
let(:append_response) { nil }
- subject { described_class.new(connection, "my_folder") }
-
context "#uids" do
let(:uids) { [5678, 123] }
before { allow(imap).to receive(:uid_search).and_return(uids) }
@@ -44,11 +44,11 @@
end
end
end
context "#fetch" do
- let(:message_body) { double("the body", force_encoding: nil) }
+ 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
@@ -132,26 +132,38 @@
let(:responses) { {"UIDVALIDITY" => ["x", "uid validity"]} }
it "is returned" do
expect(subject.uid_validity).to eq("uid validity")
end
+
+ context "when the folder doesn't exist" do
+ before do
+ allow(imap).to receive(:examine).and_raise(missing_mailbox_error)
+ end
+
+ it "raises an error" do
+ expect do
+ subject.uid_validity
+ end.to raise_error(Imap::Backup::FolderNotFound)
+ end
+ end
end
context "#append" do
let(:message) do
instance_double(
Email::Mboxrd::Message,
imap_body: "imap body",
date: Time.now
)
end
- let(:append_response) { "response" }
+ let(:append_response) do
+ OpenStruct.new(data: OpenStruct.new(code: OpenStruct.new(data: "1 2")))
+ end
let(:result) { subject.append(message) }
before do
- allow(append_response).
- to receive_message_chain("data.code.data") { "1 2" }
result
end
it "appends the message" do
expect(imap).to have_received(:append)
@@ -164,5 +176,7 @@
it "set the new uid validity" do
expect(subject.uid_validity).to eq(1)
end
end
end
+
+# rubocop:enable RSpec/PredicateMatcher