spec/unit/struct_spec.rb in a9n-0.4.0 vs spec/unit/struct_spec.rb in a9n-0.4.1
- old
+ new
@@ -1,109 +1,120 @@
-require 'spec_helper'
+require "spec_helper"
describe A9n::Struct do
context "without any values" do
subject { described_class.new }
- it 'is empty' do
- expect(subject).to be_empty
+ describe "#empty?" do
+ it { expect(subject).to be_empty }
end
- it 'raises error' do
+ describe "#keys" do
+ it { expect(subject.keys).to eq([]) }
+ end
+
+ describe "#key?" do
+ it { expect(subject.key?(:dwarf)).to eq(false) }
+ end
+
+ describe "#[]" do
+ it { expect(subject[:dwarf]).to be_nil }
+ end
+
+ it "raises error on accessin invalid attribute" do
expect {
subject.dwarf
- }.to raise_error(A9n::NoSuchConfigurationVariable, 'dwarf')
+ }.to raise_error(A9n::NoSuchConfigurationVariable, "dwarf")
end
end
context "with values" do
subject {
described_class.new({
- non_empty_dwarf: 'dwarf',
+ non_empty_dwarf: "dwarf",
nil_dwarf: nil,
false_dwarf: false,
true_dwarf: true,
- hash_dwarf: { dwarf: 'hello' }
+ hash_dwarf: { dwarf: "hello" }
})
}
- describe '#keys' do
- subject { super().keys }
-
+ describe "#keys" do
it do
- expect(subject).to eq [:non_empty_dwarf, :nil_dwarf, :false_dwarf, :true_dwarf, :hash_dwarf]
+ expect(subject.keys).to eq [:non_empty_dwarf, :nil_dwarf, :false_dwarf, :true_dwarf, :hash_dwarf]
end
end
- describe '#merge' do
+ describe "#key?" do
+ it { expect(subject.key?(:nil_dwarf)).to eq(true) }
+ it { expect(subject.key?(:unknown)).to eq(false) }
+ end
+
+ describe "#merge" do
before { subject.merge(argument) }
- context 'hash' do
- let(:argument) { { non_empty_dwarf: 'hello dwarf' } }
+ context "hash" do
+ let(:argument) { { non_empty_dwarf: "hello dwarf" } }
it do
- expect(subject.non_empty_dwarf).to eq('hello dwarf')
+ expect(subject.non_empty_dwarf).to eq("hello dwarf")
end
end
- context 'struct' do
- let(:argument) { described_class.new(non_empty_dwarf: 'hello dwarf') }
+ context "struct" do
+ let(:argument) { described_class.new(non_empty_dwarf: "hello dwarf") }
it do
- expect(subject.non_empty_dwarf).to eq('hello dwarf')
+ expect(subject.non_empty_dwarf).to eq("hello dwarf")
end
end
end
- it 'is not empty' do
+ it "is not empty" do
expect(subject).not_to be_empty
end
- it 'gets non-empty value' do
- expect(subject.non_empty_dwarf).to eq('dwarf')
+ it "gets non-empty value" do
+ expect(subject.non_empty_dwarf).to eq("dwarf")
end
- it 'gets nil value' do
+ it "gets nil value" do
expect(subject.nil_dwarf).to eq(nil)
end
- it 'gets true value' do
+ it "gets true value" do
expect(subject.true_dwarf).to eq(true)
end
- it 'gets false value' do
+ it "gets false value" do
expect(subject.false_dwarf).to eq(false)
end
- it 'gets hash value' do
+ it "gets hash value" do
expect(subject.hash_dwarf).to be_kind_of(Hash)
end
- it 'raises exception when value not exists' do
+ it "raises exception when value not exists" do
expect {
subject.non_existing_dwarf
}.to raise_error(A9n::NoSuchConfigurationVariable)
end
- describe '#fetch' do
- it 'return non empty value' do
- expect(subject.fetch(:non_empty_dwarf)).to eq('dwarf')
+ describe "#[]" do
+ it "return non empty value" do
+ expect(subject[:non_empty_dwarf]).to eq("dwarf")
end
- it 'return false value' do
- expect(subject.fetch(:false_dwarf)).to eq(false)
+ it "return false value" do
+ expect(subject[:false_dwarf]).to eq(false)
end
- it 'return nil value' do
- expect(subject.fetch(:nil_dwarf)).to eq(nil)
+ it "return nil value" do
+ expect(subject[:nil_dwarf]).to eq(nil)
end
- it 'return nil for non existing value' do
- expect(subject.fetch(:non_existing_dwarf)).to eq(nil)
- end
-
- it 'return default for non existing value' do
- expect(subject.fetch(:non_existing_dwarf, 'default')).to eq('default')
+ it "return nil for non existing value" do
+ expect(subject[:non_existing_dwarf]).to eq(nil)
end
end
end
end