Skip to content

Commit

Permalink
Simplify class after class extraction
Browse files Browse the repository at this point in the history
* Now we have Email::provider there's no need to test specific cases.
  • Loading branch information
joeyates committed Oct 14, 2015
1 parent 60d3915 commit bc05fdd
Showing 1 changed file with 10 additions and 37 deletions.
47 changes: 10 additions & 37 deletions spec/unit/account/connection_spec.rb
Expand Up @@ -10,7 +10,7 @@ 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
{
Expand All @@ -30,17 +30,13 @@ def self.folder_config

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

Expand All @@ -54,38 +50,16 @@ def self.folder_config
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
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
Expand Down Expand Up @@ -188,7 +162,6 @@ def self.folder_config
end

context '#disconnect' do
before { allow(imap).to receive(:disconnect) }
before { subject.disconnect }

it 'disconnects from the server' do
Expand Down

0 comments on commit bc05fdd

Please sign in to comment.