Sha256: 42e07bf8f08fb1bf9fa7d9c2a4952f5bef79875473b6feee3962cf9ca7ff73a6

Contents?: true

Size: 1.99 KB

Versions: 30

Compression:

Stored size: 1.99 KB

Contents

require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")

module RR
  describe HashWithObjectIdKey do
    describe "#[] and #[]=" do
      it "stores object via object id" do
        hash = HashWithObjectIdKey.new
        array_1 = []
        hash[array_1] = 1
        array_2 = []
        hash[array_2] = 2

        hash[array_1].should_not == hash[array_2]
      end

      it "stores the passed in object" do
        hash = HashWithObjectIdKey.new
        obj = Object.new
        hash[obj] = 1
        hash.instance_eval {@keys}.should == {obj.__id__ => obj}
      end
    end

    describe "#each" do
      it "iterates through the items in the hash" do
        hash = HashWithObjectIdKey.new
        hash['one'] = 1
        hash['two'] = 2

        keys = []
        values = []
        hash.each do |key, value|
          keys << key
          values << value
        end

        keys.sort.should == ['one', 'two']
        values.sort.should == [1, 2]
      end
    end

    describe "#delete" do
      before do
        @hash = HashWithObjectIdKey.new
        @key = Object.new
        @hash[@key] = 1
      end

      it "removes the object from the hash" do
        @hash.delete(@key)
        @hash[@key].should be_nil
      end

      it "removes the object from the keys hash" do
        @hash.delete(@key)
        @hash.instance_eval {@keys}.should == {}
      end
    end

    describe "#keys" do
      before do
        @hash = HashWithObjectIdKey.new
        @key = Object.new
        @hash[@key] = 1
      end

      it "returns an array of the keys" do
        @hash.keys.should == [@key]
      end
    end

    describe "#include?" do
      before do
        @hash = HashWithObjectIdKey.new
        @key = Object.new
        @hash[@key] = 1
      end

      it "returns true when the key is in the Hash" do
        @hash.include?(@key).should be_true
      end

      it "returns false when the key is not in the Hash" do
        @hash.include?(Object.new).should be_false
      end
    end
  end
end

Version data entries

30 entries across 26 versions & 5 rubygems

Version Path
bitclust-core-0.5.3 vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.3/vendor/bundle/ruby/1.9.1/gems/rr-1.0.4/spec/rr/space/hash_with_object_id_key_spec.rb
bitclust-core-0.5.3 vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.3/vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.1/vendor/bundle/ruby/1.9.1/gems/rr-1.0.4/spec/rr/space/hash_with_object_id_key_spec.rb
bitclust-core-0.5.3 vendor/bundle/ruby/1.9.1/gems/rr-1.0.4/spec/rr/space/hash_with_object_id_key_spec.rb
bitclust-core-0.5.3 vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.1/vendor/bundle/ruby/1.9.1/gems/rr-1.0.4/spec/rr/space/hash_with_object_id_key_spec.rb
bitclust-core-0.5.2 vendor/bundle/ruby/1.9.1/gems/rr-1.0.4/spec/rr/space/hash_with_object_id_key_spec.rb
bitclust-core-0.5.2 vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.1/vendor/bundle/ruby/1.9.1/gems/rr-1.0.4/spec/rr/space/hash_with_object_id_key_spec.rb
bitclust-core-0.5.1 vendor/bundle/ruby/1.9.1/gems/rr-1.0.4/spec/rr/space/hash_with_object_id_key_spec.rb
mcmire-rr-1.0.5.rc1 spec/rr/space/hash_with_object_id_key_spec.rb
messagebus_ruby_api-0.4.7 spec/ruby/1.9.1/gems/rr-1.0.2/spec/rr/space/hash_with_object_id_key_spec.rb
messagebus_ruby_api-0.4.4 spec/ruby/1.9.1/gems/rr-1.0.2/spec/rr/space/hash_with_object_id_key_spec.rb
rr-1.0.4 spec/rr/space/hash_with_object_id_key_spec.rb
rr-1.0.3 spec/rr/space/hash_with_object_id_key_spec.rb
vim-jar-0.1.2.0001 bundler/ruby/1.8/gems/rr-1.0.2/spec/rr/space/hash_with_object_id_key_spec.rb
vim-jar-0.1.2 bundler/ruby/1.8/gems/rr-1.0.2/spec/rr/space/hash_with_object_id_key_spec.rb
vim-jar-0.1.1 bundler/ruby/1.8/gems/rr-1.0.2/spec/rr/space/hash_with_object_id_key_spec.rb
vim-jar-0.1.0 bundler/ruby/1.8/gems/rr-1.0.2/spec/rr/space/hash_with_object_id_key_spec.rb
vim-jar-0.0.3 bundler/ruby/1.8/gems/rr-1.0.2/spec/rr/space/hash_with_object_id_key_spec.rb
vim-jar-0.0.2 bundler/ruby/1.8/gems/rr-1.0.2/spec/rr/space/hash_with_object_id_key_spec.rb
vim-jar-0.0.1 bundler/ruby/1.8/gems/rr-1.0.2/spec/rr/space/hash_with_object_id_key_spec.rb
rr-1.0.2 spec/rr/space/hash_with_object_id_key_spec.rb