Sha256: 0b7855fef860065455cfd8dd9f82a5b8107253465c086cdf8fa5aead1c8d114d

Contents?: true

Size: 1.56 KB

Versions: 4

Compression:

Stored size: 1.56 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

require 'hamster/hash'

describe Hamster::Hash do

  [:eql?, :==].each do |method|

    describe "##{method}" do

      describe "returns false when comparing with" do

        before do
          @hash = Hamster.hash("A" => "aye", "B" => "bee", "C" => "see")
        end

        it "a standard hash" do
          @hash.send(method, "A" => "aye", "B" => "bee", "C" => "see").should be_false
        end

        it "an aribtrary object" do
          @hash.send(method, Object.new).should be_false
        end

      end

      [
        [{}, {}, true],
        [{"A" => "aye"}, {}, false],
        [{}, {"A" => "aye"}, false],
        [{"A" => "aye"}, {"A" => "aye"}, true],
        [{"A" => "aye"}, {"B" => "bee"}, false],
        [{"A" => "aye", "B" => "bee"}, {"A" => "aye"}, false],
        [{"A" => "aye"}, {"A" => "aye", "B" => "bee"}, false],
        [{"A" => "aye", "B" => "bee", "C" => "see"}, {"A" => "aye", "B" => "bee", "C" => "see"}, true],
        [{"C" => "see", "A" => "aye", "B" => "bee"}, {"A" => "aye", "B" => "bee", "C" => "see"}, true],
      ].each do |a, b, expected|

        describe "returns #{expected.inspect}" do

          before do
            @a = Hamster.hash(a)
            @b = Hamster.hash(b)
          end

          it "for #{a.inspect} and #{b.inspect}" do
            @a.send(method, @b).should == expected
          end

          it "for #{b.inspect} and #{a.inspect}" do
            @b.send(method, @a).should == expected
          end

        end

      end

    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hamster-0.1.19 spec/hamster/hash/eql_spec.rb
hamster-0.1.18 spec/hamster/hash/eql_spec.rb
hamster-0.1.17 spec/hamster/hash/eql_spec.rb
hamster-0.1.16 spec/hamster/hash/eql_spec.rb