Sha256: c51714e18be7c184e36296903c59102cafa54af5e773b5f86543563c6a535ddc

Contents?: true

Size: 1.26 KB

Versions: 8

Compression:

Stored size: 1.26 KB

Contents

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

require 'hamster/hash'

describe Hamster::Hash do

  [:reject, :delete_if].each do |method|

    describe "##{method}" do

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

      describe "when nothing matches" do

        before do
          @result = @original.send(method) { |key, value| false }
        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("B" => "bee", "C" => "see")
          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

8 entries across 8 versions & 1 rubygems

Version Path
hamster-0.1.22 spec/hamster/hash/reject_spec.rb
hamster-0.1.21 spec/hamster/hash/reject_spec.rb
hamster-0.1.20 spec/hamster/hash/reject_spec.rb
hamster-0.1.19 spec/hamster/hash/reject_spec.rb
hamster-0.1.18 spec/hamster/hash/reject_spec.rb
hamster-0.1.17 spec/hamster/hash/reject_spec.rb
hamster-0.1.16 spec/hamster/hash/reject_spec.rb
hamster-0.1.15 spec/hamster/hash/reject_spec.rb