Sha256: 25c0effa5e6dff6855eba80a8bc1818f424158067dbd427113a80ff945378611

Contents?: true

Size: 1.31 KB

Versions: 3

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

RSpec.describe SoapyBing::ParamGuard do
  describe '#require!' do
    let(:param_guard) { described_class.new(options, env_namespace: 'MY') }

    subject(:require_foo) { param_guard.require!(:foo) }

    context 'when option is empty' do
      let(:options) { {} }

      context 'and environment variable is empty too' do
        it 'thows exception' do
          expect { require_foo }.to raise_exception SoapyBing::ParamGuard::ParamRequiredError,
            'foo have to be passed explicitly or via ENV[\'MY_FOO\']'
        end
      end

      context 'but environment variable is present' do
        before { allow(ENV).to receive(:[]).with('MY_FOO').and_return('bar_env') }

        it 'returns environment variable value' do
          expect(require_foo).to eq 'bar_env'
        end
      end
    end

    context 'when option is present' do
      let(:options) { { foo: 'bar' } }

      context 'and environment variable is present too' do
        before { allow(ENV).to receive(:[]).with('MY_FOO').and_return('bar_env') }

        it 'returns option value' do
          expect(require_foo).to eq 'bar'
        end
      end

      context 'but environment variable is empty' do
        it 'returns option value' do
          expect(require_foo).to eq 'bar'
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
soapy_bing-1.0.1 spec/soapy_bing/param_guard_spec.rb
soapy_bing-1.0.0 spec/soapy_bing/param_guard_spec.rb
soapy_bing-0.4.0 spec/soapy_bing/param_guard_spec.rb