Sha256: 0ca8b5969e6d18152618bdc7502174b7783b83be6b7a1fa240dc0af478350878

Contents?: true

Size: 1.21 KB

Versions: 7

Compression:

Stored size: 1.21 KB

Contents

require 'spec_helper'

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

7 entries across 7 versions & 1 rubygems

Version Path
hamster-0.4.3 spec/hamster/hash/filter_spec.rb
hamster-0.4.2 spec/hamster/hash/filter_spec.rb
hamster-0.4.0 spec/hamster/hash/filter_spec.rb
hamster-0.3.10 spec/hamster/hash/filter_spec.rb
hamster-0.3.9 spec/hamster/hash/filter_spec.rb
hamster-0.3.8 spec/hamster/hash/filter_spec.rb
hamster-0.3.7 spec/hamster/hash/filter_spec.rb