Sha256: 490f5dfa5d89a2318f488fe3bca5ec6b8cff3200d57339cb6c9310d9640301f8

Contents?: true

Size: 1.78 KB

Versions: 1

Compression:

Stored size: 1.78 KB

Contents

require 'spec_helper'
require 'set'

describe HammerStore do
  describe '#new' do
    it 'creates store objects' do
      test = HammerStore.new file: 'teststore'
      expect(test).to be_an_instance_of HammerStore::Store
    end
  end

  describe HammerStore::Store do
    let(:keys) { [1, 2, 3, 4, 5, :foo, 'foo'].to_set }
    let(:store) do
      store = HammerStore::Store.new file: 'teststore'
      store.clear!
      (1..5).each { |i| store[i] = i + 5 }
      store[:foo] = :bar
      store['foo'] = 'bar'
      store
    end

    describe '#initialize' do
      it 'creates a new store raw object' do
        expect(store.raw).to be_an_instance_of Hammerspace::Hash
      end
    end
    describe '#clear!' do
      describe 'when given no argument' do
        it 'empties the store' do
          expect(store.clear!).to eql Hash.new
        end
      end
      describe 'when given an argument' do
        it 'removes a key from the store' do
          old_size = store.size
          store.clear! 1
          expect(store.size).to eql old_size - 1
        end
      end
    end
    describe '#[]' do
      it 'retrieves a key' do
        expect(store[1]).to eql 6
        expect(store[:foo]).to eql :bar
        expect(store['foo']).to eql 'bar'
      end
    end
    describe '#[]=' do
      it 'sets a key' do
        expect(store[6] = 10).to eql 10
      end
    end
    describe '#size' do
      it 'returns the size of the store' do
        expect(store.size).to eql 7
      end
    end
    describe '#include?' do
      it 'checks for a key in the store' do
        expect(store.include? :fish).to be_false
        expect(store.include? 1).to be_true
      end
    end
    describe '#keys' do
      it 'lists the keys in the store' do
        expect(store.keys.to_set).to eql keys
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hammerstore-0.0.2 spec/hammerstore_spec.rb