Sha256: 0a67a376c774df7c6319c3d88469c1c2e4da2d7912fe35de4acb0f00781be847

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

require "spec_helper"

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
          [
            %w[A aye],
            %w[B bee],
            %w[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

1 entries across 1 versions & 1 rubygems

Version Path
hamster-1.0.1.pre.rc.1 spec/hamster/hash/any_spec.rb