spec/unit/account/connection_spec.rb in imap-backup-1.0.17 vs spec/unit/account/connection_spec.rb in imap-backup-1.1.0
- old
+ new
@@ -8,11 +8,11 @@
def self.folder_config
{:name => backup_folder}
end
- let(:imap) { double('Net::IMAP', :login => nil, :list => imap_folders) }
+ let(:imap) { double('Net::IMAP', :login => nil, :list => imap_folders, :disconnect => nil) }
let(:imap_folders) { [] }
let(:options) do
{
:username => username,
:password => 'password',
@@ -24,25 +24,22 @@
let(:backup_folders) { [self.class.folder_config] }
let(:username) { 'username@gmail.com' }
before do
allow(Net::IMAP).to receive(:new).and_return(imap)
+ allow(Imap::Backup::Utils).to receive(:make_folder)
end
subject { described_class.new(options) }
- shared_examples 'connects to IMAP' do |options|
- options ||= {}
- username = options[:username] || 'username@gmail.com'
- server = options[:server] || 'imap.gmail.com'
-
+ shared_examples 'connects to IMAP' do
it 'sets up the IMAP connection' do
- expect(Net::IMAP).to have_received(:new).with(server, {:port => 993, :ssl => true})
+ expect(Net::IMAP).to have_received(:new)
end
it 'logs in to the imap server' do
- expect(imap).to have_received(:login).with(username, 'password')
+ expect(imap).to have_received(:login)
end
end
context '#initialize' do
[
@@ -53,41 +50,24 @@
it "expects #{attr}" do
expect(subject.send(attr)).to eq(expected)
end
end
- context 'server' do
- context 'with a supplied value' do
- before do
- options.merge!(:server => 'imap.example.com')
- end
-
- it 'uses the supplied value' do
- expect(subject.server).to eq('imap.example.com')
- end
- end
-
- context 'without a supplied value' do
- it 'uses the guesses the value' do
- expect(subject.server).to eq('imap.gmail.com')
- end
- end
+ it 'creates the path' do
+ subject.username
+ expect(Imap::Backup::Utils).to have_received(:make_folder)
end
end
- [
- ['GMail', 'user@gmail.com', 'imap.gmail.com'],
- ['Fastmail', 'user@fastmail.fm', 'mail.messagingengine.com'],
- ].each do |service, email_username, server|
- context service do
- let(:username) { email_username }
+ describe '#imap' do
+ before { @result = subject.imap }
- before { allow(imap).to receive(:disconnect) }
- before { subject.disconnect }
-
- include_examples 'connects to IMAP', {:username => email_username, :server => server}
+ it 'returns the IMAP connection' do
+ expect(@result).to eq(imap)
end
+
+ include_examples 'connects to IMAP'
end
context '#folders' do
let(:imap_folders) { ['imap_folder'] }
@@ -120,23 +100,12 @@
it 'should retrieve the available uids' do
expect(subject.status[0][:remote]).to eq([remote_uid])
end
end
- context '#disconnect' do
- before { allow(imap).to receive(:disconnect) }
- before { subject.disconnect }
-
- it 'disconnects from the server' do
- expect(imap).to have_received(:disconnect)
- end
-
- include_examples 'connects to IMAP'
- end
-
context '#run_backup' do
- let(:folder) { double('folder') }
+ let(:folder) { double('folder', name: 'folder') }
let(:serializer) { double('serializer') }
let(:downloader) { double('downloader', :run => nil) }
before do
allow(Imap::Backup::Downloader).to receive(:new).and_return(downloader)
@@ -194,7 +163,17 @@
it 'does not fail' do
expect { subject.run_backup }.to_not raise_error
end
end
end
+ end
+
+ context '#disconnect' do
+ before { subject.disconnect }
+
+ it 'disconnects from the server' do
+ expect(imap).to have_received(:disconnect)
+ end
+
+ include_examples 'connects to IMAP'
end
end