Sha256: a10a570fd249736560f27994c1199eb134cb1bd1a9b3f7d94c1e58b52c70833a

Contents?: true

Size: 1.95 KB

Versions: 3

Compression:

Stored size: 1.95 KB

Contents

# frozen_string_literal: true

describe '(#subset)-functionality' do
  specify '#subset functionality works as expected :)' do
    class SubsetableConfig < Qonfig::DataSet
      setting :db do
        setting :creds do
          setting :user, 'D@iVeR'
          setting :data, test: false
        end
      end

      setting :adapter, :sidekiq
    end

    config = SubsetableConfig.new

    # access to the subset (with indifferent keys type)
    expect(config.subset(:db, ['db', :creds], ['db', 'creds', :user], 'adapter')).to match(
      'db' => { 'creds' => { 'user' => 'D@iVeR', 'data' => { test: false } } }, # :db
      'creds' => { 'user' => 'D@iVeR', 'data' => { test: false } }, # ['db', :creds]
      'user' => 'D@iVeR', # ['db', 'creds', :user]
      'adapter' => :sidekiq # 'adepter'
    )

    # try to use subset with with unexistent keys
    # NOTE: :megazavr key does not exist
    expect { config.subset(%i[db creds megazavr]) }.to raise_error(Qonfig::UnknownSettingError)
    # NOTE: :test key does not exist
    expect { config.subset(:db, :test) }.to raise_error(Qonfig::UnknownSettingError)

    # you cant use subset operation over setting values - you can do it only over the setting keys!
    expect { config.subset(%i[db creds data test]) }.to raise_error(Qonfig::UnknownSettingError)

    # subset invokation with empty key list
    # rubocop:disable Lint/RedundantSplatExpansion
    expect(config.subset(*[])).to eq({})
    expect(config.subset).to eq({})
    # rubocop:enable Lint/RedundantSplatExpansion

    # subset invokation over unexistent option
    expect { config.subset(%i[db creds session]) }.to raise_error(Qonfig::UnknownSettingError)
    expect { config.subset(%i[a b c d]) }.to raise_error(Qonfig::UnknownSettingError)

    # invokation with incorret subset key attributes
    expect { config.subset([:db, :creds, Object.new]) }.to raise_error(Qonfig::ArgumentError)
    expect { config.subset(:db, 123) }.to raise_error(Qonfig::ArgumentError)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
qonfig-0.28.0 spec/features/subset_functionality_spec.rb
qonfig-0.27.0 spec/features/subset_functionality_spec.rb
qonfig-0.26.0 spec/features/subset_functionality_spec.rb