Skip to content

Commit

Permalink
Improve test coverage for configuration (#691)
Browse files Browse the repository at this point in the history
* Improve test coverage for configuration

* Check that set? returns false if value is nil
  • Loading branch information
lovro-bikic authored Aug 17, 2021
1 parent 0722fdb commit 87490e6
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions spec/lib/mina/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 }
Expand Down

0 comments on commit 87490e6

Please sign in to comment.