spec/unit/configuration/account_spec.rb in imap-backup-1.0.14 vs spec/unit/configuration/account_spec.rb in imap-backup-1.0.15

- old
+ new

@@ -18,16 +18,10 @@ choices[name] = block end end context '#initialize' do - it 'requires 3 parameters' do - expect do - described_class.new('foo') - end.to raise_error(ArgumentError, /1 for 3/) - end - let(:store) { 'store' } let(:account) { 'account' } let(:highline) { 'highline' } subject { described_class.new(store, account, highline) } @@ -169,12 +163,16 @@ end end end end - it 'modifies the email address' do - expect(account[:username]).to eq(new_email) + context 'the email is new' do + it 'modifies the email address' do + expect(account[:username]).to eq(new_email) + end + + include_examples 'it flags the account as modified' end context 'the email already exists' do let(:new_email) { other_email } @@ -183,10 +181,12 @@ end it "doesn't set the email" do expect(account[:username]).to eq(existing_email) end + + include_examples "it doesn't flag the account as modified" end end context 'password' do let(:new_password) { 'new_password' } @@ -195,20 +195,26 @@ allow(Imap::Backup::Configuration::Asker).to receive(:password).and_return(new_password) subject.run menu.choices['modify password'].call end - it 'updates the password' do - expect(account[:password]).to eq(new_password) + context 'if the user enters a password' do + it 'updates the password' do + expect(account[:password]).to eq(new_password) + end + + include_examples 'it flags the account as modified' end context 'if the user cancels' do let(:new_password) { nil } it 'does nothing' do expect(account[:password]).to eq(existing_password) end + + include_examples "it doesn't flag the account as modified" end end context 'server' do let(:server) { 'server' } @@ -223,10 +229,12 @@ end it 'updates the server' do expect(account[:server]).to eq(server) end + + include_examples 'it flags the account as modified' end context 'backup_path' do let(:new_backup_path) { '/new/path' } @@ -245,10 +253,12 @@ end it 'validates that the path is not used by other backups' do expect(@validator.call(other_existing_path)).to be_falsey end + + include_examples 'it flags the account as modified' end context 'folders' do let(:chooser) { double(:run => nil) } @@ -289,19 +299,17 @@ it 'asks for confirmation' do expect(highline).to have_received(:agree) end - it 'deletes the account' do - expect(accounts.find { |a| a[:username] == existing_email }).to be_nil + context 'when the user confirms deletion' do + include_examples 'it flags the account to be deleted' end context 'without confirmation' do let(:confirmed) { false } - it 'does nothing' do - expect(accounts.find{|a| a[:username] == existing_email}).to eq(account) - end + include_examples "it doesn't flag the account to be deleted" end end end end