Sha256: 9d9e0f1ce65b0d0997247ec0dbf0ddfd3f66304976a97d8b32cb779ecd0ec892

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

require "spec_helper"
require "hamster/hash"

describe Hamster::Hash do
  describe "#clear" do
    [
      [],
      ["A" => "aye"],
      ["A" => "aye", "B" => "bee", "C" => "see"],
    ].each do |values|
      context "on #{values}" do
        let(:original) { H[*values] }
        let(:result)   { original.clear }

        it "preserves the original" do
          result
          original.should eql(H[*values])
        end

        it "returns an empty hash" do
          result.should equal(H.empty)
          result.should be_empty
        end
      end
    end

    it "maintains the default Proc, if there is one" do
      hash = H.new(a: 1) { 1 }
      hash.clear[:b].should == 1
      hash.clear[:c].should == 1
      hash.clear.default_proc.should_not be_nil
    end

    context "on a subclass" do
      it "returns an empty instance of the subclass" do
        subclass = Class.new(Hamster::Hash)
        instance = subclass.new(a: 1, b: 2)
        instance.clear.class.should be(subclass)
        instance.clear.should be_empty
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/hamster-3.0.0/spec/lib/hamster/hash/clear_spec.rb
hamster-3.0.0 spec/lib/hamster/hash/clear_spec.rb
hamster-2.0.0 spec/lib/hamster/hash/clear_spec.rb