Sha256: cd1ba0136fc7bc3052411130380ab22315a507ad8ca7af966954bc0c490eeadf

Contents?: true

Size: 1.38 KB

Versions: 12

Compression:

Stored size: 1.38 KB

Contents

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

require 'hamster/hash'

describe Hamster::Hash do

  [:any?, :exist?, :exists?].each do |method|

    describe "##{method}" do

      describe "when empty" do

        before do
          @hash = Hamster.hash
        end

        it "with a block returns false" do
          @hash.send(method) {}.should == false
        end

        it "with no block returns false" do
          @hash.send(method).should == false
        end

      end

      describe "when not empty" do

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

        describe "with a block" do

          [
            ["A", "aye"],
            ["B", "bee"],
            ["C", "see"],
            [nil, "NIL"],
          ].each do |pair|

            it "returns true if the block ever returns true (#{pair.inspect})" do
              @hash.send(method) { |key, value| key == pair.first && value == pair.last }.should == true
            end

            it "returns false if the block always returns false" do
              @hash.send(method) { |key, value| key == "D" && value == "dee" }.should == false
            end

          end

        end

        describe "with no block" do

          it "returns true" do
            @hash.send(method).should == true
          end

        end

      end

    end

  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
hamster-0.3.6 spec/hamster/hash/any_spec.rb
hamster-0.3.5 spec/hamster/hash/any_spec.rb
hamster-0.3.4 spec/hamster/hash/any_spec.rb
hamster-0.3.3 spec/hamster/hash/any_spec.rb
hamster-0.3.2 spec/hamster/hash/any_spec.rb
hamster-0.3.1 spec/hamster/hash/any_spec.rb
hamster-0.3.0 spec/hamster/hash/any_spec.rb
hamster-0.2.13 spec/hamster/hash/any_spec.rb
hamster-0.2.12 spec/hamster/hash/any_spec.rb
hamster-0.2.11 spec/hamster/hash/any_spec.rb
hamster-0.2.9 spec/hamster/hash/any_spec.rb
hamster-0.2.8 spec/hamster/hash/any_spec.rb