require 'spec_helper' RSpec.describe ComplexConfig::Settings do before do # Disable all plugins for this spec b/c they interfere with how rspec works allow(ComplexConfig::Provider.instance).to receive(:plugins).and_return([]) end let :settings do ComplexConfig::Settings[ foo: { bar: { baz: true }, qux: 'quux' } ] end it 'can be initialized with a hash' do s = ComplexConfig::Settings.new(foo: 'bar') expect(s.foo).to eq 'bar' end it 'can be duped and changed' do s = ComplexConfig::Settings.new(foo: 'bar') t = s.dup expect(s.foo).to eq 'bar' t.foo = 'baz' expect(s.foo).to eq 'bar' expect(t.foo).to eq 'baz' end it 'can set its attributes' do expect { settings.blub = 'blub' }.to change { settings.blub? }.from(nil).to('blub') end it 'has a size' do expect(settings.size).to eq 1 end it 'can set its attributes via index method' do expect { settings['blub'] = 'blub' }.to change { settings.blub? }.from(nil).to('blub') end it "can return an attribute's value" do expect(settings.foo.bar.baz).to eq true end it 'can display its attribute_names' do expect(settings.foo.attribute_names).to eq [ :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 return a hash with pathes as keys' do expect(settings.pathes(path_sep: ?:)).to eq( 'foo:bar:baz' => true, 'foo:qux' => "quux" ) end it 'can be represented as a string' do expect(settings.to_s(pair_sep: ' → ', path_sep: ?/)).to eq <