spec/unit/imap/backup/account/folder_spec.rb in imap-backup-3.0.0 vs spec/unit/imap/backup/account/folder_spec.rb in imap-backup-3.1.0

- old
+ new

@@ -1,10 +1,13 @@ # rubocop:disable RSpec/PredicateMatcher describe Imap::Backup::Account::Folder do - subject { described_class.new(connection, "my_folder") } + FOLDER_NAME = "Gelöscht" + ENCODED_FOLDER_NAME = "Gel&APY-scht" + subject { described_class.new(connection, FOLDER_NAME) } + let(:imap) do instance_double( Net::IMAP, append: append_response, create: nil, @@ -14,11 +17,11 @@ end let(:connection) do instance_double(Imap::Backup::Account::Connection, imap: imap) end let(:missing_mailbox_data) do - OpenStruct.new(text: "Unknown Mailbox: my_folder") + OpenStruct.new(text: "Unknown Mailbox: #{FOLDER_NAME}") end let(:missing_mailbox_response) { OpenStruct.new(data: missing_mailbox_data) } let(:missing_mailbox_error) do Net::IMAP::NoResponseError.new(missing_mailbox_response) end @@ -34,11 +37,12 @@ expect(subject.uids).to eq(uids.reverse) end context "with missing mailboxes" do before do - allow(imap).to receive(:examine).and_raise(missing_mailbox_error) + allow(imap).to receive(:examine). + with(ENCODED_FOLDER_NAME).and_raise(missing_mailbox_error) end it "returns an empty array" do expect(subject.uids).to eq([]) end @@ -48,11 +52,12 @@ let(:no_method_error) do NoMethodError.new("Somethimes SEARCH responses come out undefined") end before do - allow(imap).to receive(:examine).and_raise(no_method_error) + allow(imap).to receive(:examine). + with(ENCODED_FOLDER_NAME).and_raise(missing_mailbox_error) end it "returns an empty array" do expect(subject.uids).to eq([]) end @@ -80,11 +85,12 @@ end end context "when the mailbox doesn't exist" do before do - allow(imap).to receive(:examine).and_raise(missing_mailbox_error) + allow(imap).to receive(:examine). + with(ENCODED_FOLDER_NAME).and_raise(missing_mailbox_error) end it "is nil" do expect(subject.fetch(123)).to be_nil end @@ -99,11 +105,11 @@ end end describe "#folder" do it "is the name" do - expect(subject.folder).to eq("my_folder") + expect(subject.folder).to eq(FOLDER_NAME) end end describe "#exist?" do context "when the folder exists" do @@ -112,11 +118,12 @@ end end context "when the folder doesn't exist" do before do - allow(imap).to receive(:examine).and_raise(missing_mailbox_error) + allow(imap).to receive(:examine). + with(ENCODED_FOLDER_NAME).and_raise(missing_mailbox_error) end it "is false" do expect(subject.exist?).to be_falsey end @@ -132,18 +139,25 @@ end end context "when the folder doesn't exist" do before do - allow(imap).to receive(:examine).and_raise(missing_mailbox_error) + allow(imap).to receive(:examine). + with(ENCODED_FOLDER_NAME).and_raise(missing_mailbox_error) end - it "is does not create the folder" do + it "creates the folder" do expect(imap).to receive(:create) subject.create end + + it "encodes the folder name" do + expect(imap).to receive(:create).with(ENCODED_FOLDER_NAME) + + subject.create + end end end describe "#uid_validity" do let(:responses) { {"UIDVALIDITY" => ["x", "uid validity"]} } @@ -152,10 +166,11 @@ 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) + allow(imap).to receive(:examine). + with(ENCODED_FOLDER_NAME).and_raise(missing_mailbox_error) end it "raises an error" do expect do subject.uid_validity