Sha256: fc1afbedf442a8edd91d9cbc4bf937aba42fe17f8294a3fe4ded6d7130a1d1af

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

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

require 'hamster/tuple'
require 'hamster/hash'

describe Hamster::Hash do

  [:find, :detect].each do |method|

    describe "##{method}" do

      [
        [[], "A", nil],
        [[], nil, nil],
        [["A" => "aye"], "A", Hamster::Tuple.new("A", "aye")],
        [["A" => "aye"], "B", nil],
        [["A" => "aye"], nil, nil],
        [["A" => "aye", "B" => "bee", nil => "NIL"], "A", Hamster::Tuple.new("A", "aye")],
        [["A" => "aye", "B" => "bee", nil => "NIL"], "B", Hamster::Tuple.new("B", "bee")],
        [["A" => "aye", "B" => "bee", nil => "NIL"], nil, Hamster::Tuple.new(nil, "NIL")],
        [["A" => "aye", "B" => "bee", nil => "NIL"], "C", nil],
      ].each do |values, key, expected|

        describe "on #{values.inspect}" do

          before do
            @hash = Hamster.hash(*values)
          end

          describe "with a block" do

            before do
              @result = @hash.send(method) { |x| x == key }
            end

            it "returns #{expected.inspect}" do
              @result.should == expected
            end

          end

          describe "without a block" do

            it "returns nil" do
              @hash.send(method).should be_nil
            end

          end

        end

      end

    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hamster-0.2.7 spec/hamster/hash/find_spec.rb
hamster-0.2.6 spec/hamster/hash/find_spec.rb