Sha256: 5d188501d80a30955f5042b39c6fd3f4496dba853e64f50d319fc0bfb477165e
Contents?: true
Size: 1.52 KB
Versions: 3
Compression:
Stored size: 1.52 KB
Contents
require "spec_helper" describe TFG::Support::DeepHashAccessor do let(:hash) { Hash.new } subject(:accessor) { TFG::Support::DeepHashAccessor.new(hash) } describe "#[]" do context "with a single argument" do subject(:call) { accessor[:foo] } context "when the key is present" do let(:hash) { {foo: :bar} } specify { expect(call).to eq :bar } end context "when the key is not present" do specify { expect(call).to be_nil } end end context "with multiple arguments" do subject(:call) { accessor[:foo, :bar, :baz] } context "when key chain is present" do let(:hash) { {foo: {bar: {baz: :qux}}} } specify { expect(call).to eq :qux } end context "when key chain is not present" do let(:hash) { {foo: {baz: {bar: :qux}}} } specify { expect(call).to be_nil } end end end describe "#[]=" do context "with a single argument" do subject(:call) { accessor[:foo] = :bar } context "when the key is present" do specify { call; expect(hash[:foo]).to eq :bar } end end context "with multiple arguments" do subject(:call) { accessor[:foo, :bar, :baz] = :qux } context "when key chain is present" do let(:hash) { {foo: {bar: {}}} } specify { call; expect(hash[:foo][:bar][:baz]).to eq :qux } end context "when key chain is not present" do specify { call; expect(hash[:foo][:bar][:baz]).to eq :qux } end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
tfg_support-1.1.1 | spec/tfg/support/deep_hash_accessor_spec.rb |
tfg_support-1.0.1 | spec/tfg/support/deep_hash_accessor_spec.rb |
tfg_support-1.0.0 | spec/tfg/support/deep_hash_accessor_spec.rb |