spec/unit/account/connection_spec.rb in imap-backup-0.0.5 vs spec/unit/account/connection_spec.rb in imap-backup-1.0.0

- old
+ new

@@ -1,24 +1,30 @@ # encoding: utf-8 -load File.expand_path( '../../spec_helper.rb', File.dirname(__FILE__) ) +require 'spec_helper' describe Imap::Backup::Account::Connection do - context '#initialize' do - it 'should login to the imap server' do imap = stub('Net::IMAP') Net::IMAP.should_receive(:new).with('imap.gmail.com', 993, true).and_return(imap) imap.should_receive('login').with('myuser', 'secret') Imap::Backup::Account::Connection.new(:username => 'myuser', :password => 'secret') end + context "with specific server" do + it 'should login to the imap server' do + imap = stub('Net::IMAP') + Net::IMAP.should_receive(:new).with('my.imap.example.com', 993, true).and_return(imap) + imap.should_receive('login').with('myuser', 'secret') + + Imap::Backup::Account::Connection.new(:username => 'myuser', :password => 'secret', :server => 'my.imap.example.com') + end + end end context 'instance methods' do - before :each do @imap = stub('Net::IMAP', :login => nil) Net::IMAP.stub!(:new).and_return(@imap) @account = { :username => 'myuser', @@ -44,13 +50,11 @@ subject.folders end end - context '#status' do - before :each do @folder = stub('Imap::Backup::Account::Folder', :uids => []) Imap::Backup::Account::Folder.stub!(:new).with(subject, 'my_folder').and_return(@folder) @serializer = stub('Imap::Backup::Serializer', :uids => []) Imap::Backup::Serializer::Directory.stub!(:new).with('/base/path', 'my_folder').and_return(@serializer) @@ -69,20 +73,18 @@ it 'should retrieve the available uids' do @folder.should_receive(:uids).and_return([101, 234]) subject.status[0][:remote].should == [101, 234] end - end context '#run_backup' do - before :each do @folder = stub('Imap::Backup::Account::Folder', :uids => []) Imap::Backup::Account::Folder.stub!(:new).with(subject, 'my_folder').and_return(@folder) @serializer = stub('Imap::Backup::Serializer') - Imap::Backup::Serializer::Directory.stub!(:new).with('/base/path', 'my_folder').and_return(@serializer) + Imap::Backup::Serializer::Mbox.stub!(:new).with('/base/path', 'my_folder').and_return(@serializer) @downloader = stub('Imap::Backup::Downloader', :run => nil) Imap::Backup::Downloader.stub!(:new).with(@folder, @serializer).and_return(@downloader) end it 'should instantiate folders' do @@ -90,11 +92,11 @@ subject.run_backup end it 'should instantiate serializers' do - Imap::Backup::Serializer::Directory.should_receive(:new).with('/base/path', 'my_folder').and_return(@serializer) + Imap::Backup::Serializer::Mbox.should_receive(:new).with('/base/path', 'my_folder').and_return(@serializer) subject.run_backup end it 'should instantiate downloaders' do @@ -106,12 +108,9 @@ it 'should run downloaders' do @downloader.should_receive(:run) subject.run_backup end - end - end - end