Sha256: eba2e64e3d8e82e684955e3404e574b7c0327794e6d78f2bedc161544855bff4

Contents?: true

Size: 1.62 KB

Versions: 2

Compression:

Stored size: 1.62 KB

Contents

require 'service_config/provider'

describe ServiceConfig::Provider do
  it 'provides the services as configured' do
    ENV['FOO'] = 'yo'
    service_config = build_service_config(:use_env => true) do |c|
      c.provides :foo
    end

    service_config.should respond_to(:foo)
    service_config.method(:foo).should_not be_nil
    service_config.foo.should == 'yo'
  end

  it 'raises if an environment variable is not set, if configured' do
    expect {
      build_service_config(:raise_if_nil => true) { |c| c.provides :unset }
    }.to raise_error('must set UNSET')

    expect {
      build_service_config(:raise_if_nil => false) { |c| c.provides :unset }
    }.not_to raise_error
  end

  it 'defines the value as "" if the environment variable is unset' do
    service_config = build_service_config(:raise_if_nil => false, :use_env => true) { |c| c.provides :unknown }
    service_config.unknown.should == ''
  end

  it 'provides the optional value if given and environment variable is unset' do
    service_config = build_service_config(:raise_if_nil => false, :use_env => true) { |c| c.provides :not_set, 'optional value' }
    service_config.not_set.should == 'optional value'
  end

  it 'does not look at the environment variable in the test environment' do
    ENV['NOT_SET'] = 'value'
    service_config = build_service_config(:use_env => false) { |c| c.provides :not_set }
    service_config.not_set.should == ''
  end

  def build_service_config(opts = {}, &block)
    default_opts = { :raise_if_nil => true, :use_env => true }
    ServiceConfig::Provider.new(default_opts.merge(opts)) do |config|
      block.call(config)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
service_config-0.0.2 spec/provider_spec.rb
service_config-0.0.1 spec/provider_spec.rb