Sha256: 82850f436761a9a1e876aec48cb23ff78180668b534383612a69046e495cf9ca

Contents?: true

Size: 1.56 KB

Versions: 10

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 == false
        end

        it "an aribtrary object" do
          @hash.send(method, Object.new).should == 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

10 entries across 10 versions & 1 rubygems

Version Path
hamster-0.2.5 spec/hamster/hash/eql_spec.rb
hamster-0.2.4 spec/hamster/hash/eql_spec.rb
hamster-0.2.3 spec/hamster/hash/eql_spec.rb
hamster-0.2.2 spec/hamster/hash/eql_spec.rb
hamster-0.2.1 spec/hamster/hash/eql_spec.rb
hamster-0.2.0 spec/hamster/hash/eql_spec.rb
hamster-0.1.23 spec/hamster/hash/eql_spec.rb
hamster-0.1.22 spec/hamster/hash/eql_spec.rb
hamster-0.1.21 spec/hamster/hash/eql_spec.rb
hamster-0.1.20 spec/hamster/hash/eql_spec.rb