From 87490e6029e2014da371d614ff78ed528e743aca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lovro=20Biki=C4=87?= Date: Tue, 17 Aug 2021 12:28:20 +0200 Subject: [PATCH] Improve test coverage for configuration (#691) * Improve test coverage for configuration * Check that set? returns false if value is nil --- spec/lib/mina/configuration_spec.rb | 57 +++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/spec/lib/mina/configuration_spec.rb b/spec/lib/mina/configuration_spec.rb index 9672954c..ac868bf6 100644 --- a/spec/lib/mina/configuration_spec.rb +++ b/spec/lib/mina/configuration_spec.rb @@ -26,6 +26,44 @@ expect(key).to eq 'env' ENV['key'] = nil end + + it "returns nil if a default value isn't provided" do + expect(config.fetch(:key)).to eq(nil) + end + end + + describe '#remove' do + context 'when key exists' do + before do + config.set(:key, :value) + end + + it 'removes the key' do + expect(config.set?(:key)).to eq(true) + + config.remove(:key) + + expect(config.set?(:key)).to eq(false) + end + + it 'returns key value' do + expect(config.remove(:key)).to eq(:value) + end + end + + context "when key doesn't exist" do + it "doesn't do anything" do + expect(config.set?(:key)).to eq(false) + + config.remove(:key) + + expect(config.set?(:key)).to eq(false) + end + + it 'returns nil' do + expect(config.remove(:key)).to eq(nil) + end + end end describe '#set?' do @@ -34,6 +72,11 @@ expect(config.set?(:key)).to be true end + it 'returns false if key is set with nil value' do + config.set(:key, nil) + expect(config.set?(:key)).to be false + end + it 'returns false if key is not set' do expect(config.set?(:key)).to be false end @@ -51,6 +94,20 @@ end end + describe '#reset!' do + before do + config.set(:key, :value) + end + + it 'cleans all variables' do + expect(config.variables).not_to be_empty + + config.reset! + + expect(config.variables).to be_empty + end + end + describe Mina::Configuration::DSL do let(:host_class) { Class.new { include Mina::Configuration::DSL } } let(:host) { host_class.new }