Sha256: 705f512dabcb009533240463f8fdb830a44e02a2e1d5b00a877522402e8c8f3f

Contents?: true

Size: 1.25 KB

Versions: 12

Compression:

Stored size: 1.25 KB

Contents

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

require 'hamster/hash'

describe Hamster::Hash do

  [:filter, :select, :find_all].each do |method|

    describe "##{method}" do

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

      describe "when everything matches" do

        before do
          @result = @original.send(method) { |key, value| true }
        end

        it "returns self" do
          @result.should equal(@original)
        end

      end

      describe "when only some things match" do

        describe "with a block" do

          before do
            @result = @original.send(method) { |key, value| key == "A" && value == "aye" }
          end

          it "preserves the original" do
            @original.should == Hamster.hash("A" => "aye", "B" => "bee", "C" => "see")
          end

          it "returns a set with the matching values" do
            @result.should == Hamster.hash("A" => "aye")
          end

        end

        describe "with no block" do

          before do
            @result = @original.send(method)
          end

          it "returns self" do
            @result.should equal(@original)
          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/filter_spec.rb
hamster-0.3.5 spec/hamster/hash/filter_spec.rb
hamster-0.3.4 spec/hamster/hash/filter_spec.rb
hamster-0.3.3 spec/hamster/hash/filter_spec.rb
hamster-0.3.2 spec/hamster/hash/filter_spec.rb
hamster-0.3.1 spec/hamster/hash/filter_spec.rb
hamster-0.3.0 spec/hamster/hash/filter_spec.rb
hamster-0.2.13 spec/hamster/hash/filter_spec.rb
hamster-0.2.12 spec/hamster/hash/filter_spec.rb
hamster-0.2.11 spec/hamster/hash/filter_spec.rb
hamster-0.2.9 spec/hamster/hash/filter_spec.rb
hamster-0.2.8 spec/hamster/hash/filter_spec.rb