Sha256: c12761896570345f9bae47d313903b3f7f44e5321ed7ef7d6ab27c6ceda43ef5

Contents?: true

Size: 1.58 KB

Versions: 1

Compression:

Stored size: 1.58 KB

Contents

require 'spec_helper'

RSpec.describe ComplexConfig::Settings do
  let :settings do
    ComplexConfig::Settings[
      foo: {
        bar: {
          baz: true
        },
        qux: 'quux'
      }
    ]
  end

  it 'can display its attribute_names' do
    expect(settings.foo.attribute_names).to eq %i[ bar qux ]
  end

  it 'can display its attribute_values' do
    values = settings.foo.attribute_values
    expect(values.first.to_h).to eq(baz: true)
    expect(values.last).to eq 'quux'
  end

  it 'can return the value of an attribute' do
    expect(settings.foo.bar.baz).to eq true
  end

  it 'can be converted into a hash' do
    expect(settings.foo.to_h).to eq(bar: { baz: true }, qux: 'quux')
  end

  it 'can be represented as a string' do
    expect(settings.to_s).to eq <<EOT
---
:foo:
  :bar:
    :baz: true
  :qux: quux
EOT
  end

  it 'can be array like (first level only), so puts still works' do
    expect(settings).to respond_to :to_ary
    expect(settings.to_ary).to eq [[:foo, settings.foo]]
  end

  it 'raises exception if expected attribute is missing' do
    pending "still doesn't work"
    expect { settings.nix }.to raise_error(ComplexConfig::AttributeMissing)
  end

  it 'can be checked for set attributes' do
    expect(settings.foo.attribute_set?(:bar)).to eq true
    expect(settings.foo.bar?).to be_truthy
    expect(settings.foo.attribute_set?(:baz)).to eq false
    #expect(settings.foo.baz?).to be_falsy
  end

  it 'handles arrays correctly' do
    settings = ComplexConfig::Settings[ary: [ 1, { hsh: 2 }, 3 ]]
    expect(settings.to_h).to eq(ary: [ 1, { hsh: 2 }, 3 ])
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
complex_config-0.1.1 spec/complex_config/settings_spec.rb