Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test coverage for configuration #691

Merged
merged 2 commits into from
Aug 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -50,6 +93,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