Sha256: 5b6d7ecd963ae45f03735b834de34db59676dc9b40c5d2369c1604891868200b

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

require 'duffel'

describe Duffel do
  it 'should not raise an error' do
    expect { subject }.to_not raise_error
  end

  describe '.not_an_existing_method' do
    context 'without a matching environment variable' do
      it 'should raise an error if nothing exists in the environment' do
        expect { subject.not_an_existing_method }.to raise_error(KeyError)
      end

      context 'with a fallback passed' do
        it 'should return the fallback' do
          expect(
            subject.another_non_existing_method(:fallback => 'blah')
          ).to eq 'blah'
        end

        context 'fallback is nil' do
          it 'should return nil' do
            expect(
              subject.yet_another_non_existing_method(:fallback => nil)
            ).to eq nil
          end
        end
      end
    end

    context 'with a matching environment variable' do
      before { expect(ENV).to receive(:fetch).with('AN_EXISTING_METHOD').and_return(response) }
      let(:response) { 'response' }

      it 'should return the env variable' do
        expect(subject.an_existing_method).to eq response
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
duffel-0.0.1 spec/lib/duffel_spec.rb