Sha256: 85c2c33fe54d4954bbdfe9c894c609bf133edd1b4270bc91057d9b99d62da4b2

Contents?: true

Size: 1.07 KB

Versions: 4

Compression:

Stored size: 1.07 KB

Contents

require "spec_helper"

module Nasty
  describe IdentityMap do
    let(:sut) { IdentityMap.new }

    context "when an item is added" do
      let(:item) { Item.new(:id => 187) }

      before { sut.add(item) }

      it "indicates that an item with that id is available" do
        sut.has_item_for?(item.id).should be_true
      end

      it "loads the item" do
        sut.item_for(item.id).should == item
      end

      context "when an item is evicted" do
        before { sut.evict(item) }

        it "indicates that it does not have an item for the evicted id" do
          sut.has_item_for?(item.id).should be_false
        end

        it "returns nothing" do
          sut.item_for(item.id).should be_nil
        end
      end
    end

    context "when no items have been added" do
      it "indicates that it does not have any items for any id" do
        (0..10).each do |i|
          sut.has_item_for?(i).should be_false
        end
      end
    end

    class Item
      attr_reader :id

      def initialize(attributes)
        @id = attributes[:id]
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
nasty-0.0.1395464273 spec/unit/identity_map_spec.rb
nasty-0.0.1388168019 spec/unit/identity_map_spec.rb
nasty-0.0.1388167257 spec/unit/identity_map_spec.rb
nasty-0.0.1388166944 spec/unit/identity_map_spec.rb