From cbf274fae43cb0e16480a22af956c47bb1d870a7 Mon Sep 17 00:00:00 2001 From: Lovro Bikic Date: Sat, 14 Aug 2021 16:09:25 +0200 Subject: [PATCH 1/2] Improve test coverage for configuration --- spec/lib/mina/configuration_spec.rb | 52 +++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/spec/lib/mina/configuration_spec.rb b/spec/lib/mina/configuration_spec.rb index 71a23e2a..66f184e9 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 @@ -50,6 +88,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 } From e8b6d0d281966812d7193b7f0f82cf3c8ae9774c Mon Sep 17 00:00:00 2001 From: Lovro Bikic Date: Tue, 17 Aug 2021 10:46:14 +0200 Subject: [PATCH 2/2] Check that set? returns false if value is nil --- spec/lib/mina/configuration_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/lib/mina/configuration_spec.rb b/spec/lib/mina/configuration_spec.rb index 66f184e9..d958d359 100644 --- a/spec/lib/mina/configuration_spec.rb +++ b/spec/lib/mina/configuration_spec.rb @@ -72,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