Sha256: bd0b6d1c9c849b33b3fe6dd3ab51c4eaab94b46d9622d1281d783197411482e5

Contents?: true

Size: 1.69 KB

Versions: 1

Compression:

Stored size: 1.69 KB

Contents

require 'spec_helper'

describe Dockly::Docker::Registry, :current do
  subject { described_class.new(:name => :dockly_registry) }

  describe '#authenticate!' do
    context 'when authentication is not required' do
      before { subject.authentication_required false }

      it 'does nothing' do
        ::Docker.should_not_receive(:authenticate!)
        subject.authenticate!
      end
    end

    context 'when the password has not been supplied via the DSL' do
      subject {
        described_class.new(
          :name => 'no-password',
          :email => 'fake@email.com',
          :username => 'fakeuser'
        )
      }

      before { ::Docker.stub(:authenticate!) }

      it 'prompts the user for the password' do
        ENV.should_receive(:[]).and_return('password')
        expect { subject.authenticate! }.to_not raise_error
      end
    end

    context 'when the password has been supplied via the DSL' do
      subject {
        described_class.new(
          :name => 'no-password',
          :email => 'fake@email.com',
          :password => 'fakepassword',
          :username => 'fakeuser'
        )
      }

      context 'when authentication succeeds' do
        before { ::Docker.stub(:authenticate!) }

        it 'does nothing' do
          ENV.should_not_receive(:[])
          expect { subject.authenticate! }.to_not raise_error
        end
      end

      context 'when authentication fails' do
        before do
          ::Docker.stub(:authenticate!).and_raise(::Docker::Error::AuthenticationError)
        end

        it 'raieses an error' do
          ENV.should_not_receive(:[])
          expect { subject.authenticate! }.to raise_error
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dockly-1.4.0 spec/dockly/docker/registry_spec.rb