spec/lib/configuration_spec.rb in gem_config-0.2.4 vs spec/lib/configuration_spec.rb in gem_config-0.3.0
- old
+ new
@@ -2,10 +2,11 @@
describe GemConfig::Configuration do
subject do
GemConfig::Configuration.new.tap do |configuration|
configuration.rules.has :foo, default: 'bar'
+ configuration.rules.has :bar
configuration.rules.has :count
configuration.rules.has :api_key, default: 'foobarbaz'
configuration.foo = 'pelle'
configuration.count = 123
configuration
@@ -28,10 +29,32 @@
it 'resets the configuration' do
subject.tap(&:reset).current.should eq(foo: 'bar', count: nil, api_key: 'foobarbaz')
end
end
+ describe '#unset' do
+ context 'with an existing key' do
+ context 'when that key has not been set' do
+ it 'doesnt change anything' do
+ expect { subject.unset(:bar) }.to_not change { subject.bar }
+ end
+ end
+
+ context 'when that key has been set' do
+ it 'unsets the key' do
+ expect { subject.unset(:count) }.to change { subject.count }.from(123).to(nil)
+ end
+ end
+ end
+
+ context 'with a non-existing key' do
+ it 'raises an exception' do
+ expect { subject.unset(:pelle) }.to raise_error(GemConfig::InvalidKeyError)
+ end
+ end
+ end
+
describe 'setting a configuration option' do
it 'checks if the value is allowed' do
subject.rules.should_receive :check, with: [:foo, 'bar']
subject.foo = 'bar'
end
@@ -42,14 +65,14 @@
subject.foo = 'bar'
end.to change { subject.foo }.from('pelle').to('bar')
end
it 'does not set the configuration option if the value is not allowed' do
- subject.rules.stub(:check, with: [:foo, 'bar']).and_raise(GemConfig::Rules::InvalidKeyError)
+ subject.rules.stub(:check, with: [:foo, 'bar']).and_raise(GemConfig::InvalidKeyError)
expect do
begin
subject.foo = 'bar'
- rescue GemConfig::Rules::InvalidKeyError
+ rescue GemConfig::InvalidKeyError
end
end.to_not change { subject.foo }.from('bar')
end
end