Sha256: 8d7dd724cb79f955eb7fb6dacc3d27d7b2e00ca0cfb0828af7f831c1f5970568

Contents?: true

Size: 1.28 KB

Versions: 15

Compression:

Stored size: 1.28 KB

Contents

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

require 'hamster/hash'

describe Hamster::Hash do

  [:map, :collect].each do |method|

    describe "##{method}" do

      describe "when empty" do

        before do
          @original = Hamster.hash
          @mapped = @original.send(method) {}
        end

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

      end

      describe "when not empty" do

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

        describe "with a block" do

          before do
            @mapped = @original.send(method) { |key, value| [key.downcase, value.upcase] }
          end

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

          it "returns a new hash with the mapped values" do
            @mapped.should == Hamster.hash("a" => "AYE", "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

15 entries across 15 versions & 1 rubygems

Version Path
hamster-0.2.5 spec/hamster/hash/map_spec.rb
hamster-0.2.4 spec/hamster/hash/map_spec.rb
hamster-0.2.3 spec/hamster/hash/map_spec.rb
hamster-0.2.2 spec/hamster/hash/map_spec.rb
hamster-0.2.1 spec/hamster/hash/map_spec.rb
hamster-0.2.0 spec/hamster/hash/map_spec.rb
hamster-0.1.23 spec/hamster/hash/map_spec.rb
hamster-0.1.22 spec/hamster/hash/map_spec.rb
hamster-0.1.21 spec/hamster/hash/map_spec.rb
hamster-0.1.20 spec/hamster/hash/map_spec.rb
hamster-0.1.19 spec/hamster/hash/map_spec.rb
hamster-0.1.18 spec/hamster/hash/map_spec.rb
hamster-0.1.17 spec/hamster/hash/map_spec.rb
hamster-0.1.16 spec/hamster/hash/map_spec.rb
hamster-0.1.15 spec/hamster/hash/map_spec.rb