Sha256: 3996bdc361a5fdca0ef1bf09047ba352508e8ea4fa001824b938610476874ce9

Contents?: true

Size: 1.73 KB

Versions: 29

Compression:

Stored size: 1.73 KB

Contents

require 'test_helper'

module Vedeu

  describe AssociativeStore do

    let(:described) { Vedeu::AssociativeStore }
    let(:instance)  { described.new(storage) }
    let(:storage)   { {} }

    describe '#initialize' do
      it { instance.must_be_instance_of(described) }
      it { instance.instance_variable_get('@storage').must_equal(storage) }
    end

    describe '#load' do
      let(:_name) {}

      subject { instance.load(_name) }

      context 'when the storage is empty' do
        it { subject.must_equal(nil) }
      end

      context 'when the storage is not empty' do
        let(:storage) { { hydrogen: '1', helium: '2' } }

        context 'when the named entry exists' do
          let(:_name) { :helium }

          it { subject.must_equal('2') }
        end

        context 'when the named entry does not exist' do
          let(:_name) { :beryllium }

          it { subject.must_equal(nil) }
        end
      end
    end

    describe '#reset' do
      subject { instance.reset }

      it { subject.must_be_instance_of(Hash) }
      it { subject.must_equal({}) }
    end

    describe '#save' do
      let(:data)  { [:some_data] }
      let(:_name) {}

      subject { instance.save(data, _name) }

      context 'when a name is given' do
        let(:_name) { :hydrogen }

        it { subject.must_equal(hydrogen: [:some_data]) }
      end

      context 'when a name is not given' do
        context 'when the data respond to name' do
          let(:data) { ModelTestClass.new(name: 'helium')}

          it { subject.key?('helium').must_equal(true) }
        end

        context 'when the data does not respond to name' do
          it { subject.must_equal({}) }
        end
      end
    end

  end # AssociativeStore

end # Vedeu

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
vedeu-0.4.47 test/lib/vedeu/storage/associative_store_test.rb
vedeu-0.4.46 test/lib/vedeu/storage/associative_store_test.rb
vedeu-0.4.45 test/lib/vedeu/storage/associative_store_test.rb
vedeu-0.4.44 test/lib/vedeu/storage/associative_store_test.rb
vedeu-0.4.43 test/lib/vedeu/storage/associative_store_test.rb
vedeu-0.4.42 test/lib/vedeu/storage/associative_store_test.rb
vedeu-0.4.41 test/lib/vedeu/storage/associative_store_test.rb
vedeu-0.4.40 test/lib/vedeu/storage/associative_store_test.rb
vedeu-0.4.39 test/lib/vedeu/storage/associative_store_test.rb
vedeu-0.4.38 test/lib/vedeu/storage/associative_store_test.rb
vedeu-0.4.37 test/lib/vedeu/storage/associative_store_test.rb
vedeu-0.4.36 test/lib/vedeu/storage/associative_store_test.rb
vedeu-0.4.35 test/lib/vedeu/storage/associative_store_test.rb
vedeu-0.4.34 test/lib/vedeu/storage/associative_store_test.rb
vedeu-0.4.33 test/lib/vedeu/storage/associative_store_test.rb
vedeu-0.4.32 test/lib/vedeu/storage/associative_store_test.rb
vedeu-0.4.31 test/lib/vedeu/storage/associative_store_test.rb
vedeu-0.4.30 test/lib/vedeu/storage/associative_store_test.rb
vedeu-0.4.29 test/lib/vedeu/storage/associative_store_test.rb
vedeu-0.4.28 test/lib/vedeu/storage/associative_store_test.rb