<commit_before>require "spec_helper"

require "hamster/hash"

describe Hamster::Hash do
  [:get, :[]].each do |method|
    describe "##{method}" do
      describe "with a default block" do
        describe "when the key exists" do
          before do
            @hash = Hamster.hash("A" => "aye") { |key| fail }
          end

          it "returns the value associated with the key" do
            @hash.get("A").should == "aye"
          end
        end

        describe "when the key does not exist" do
          before do
            @hash = Hamster.hash("A" => "aye") do |key|
              expect(key).to eq("B")
              "bee"
            end
          end

          it "returns the value associated with the key" do
            @hash.get("B").should == "bee"
          end
        end
      end

      describe "with no default block" do
        before do
          @hash = Hamster.hash("A" => "aye", "B" => "bee", "C" => "see", nil => "NIL")
        end

        [
          %w[A aye],
          %w[B bee],
          %w[C see],
          [nil, "NIL"]
        ].each do |key, value|
          it "returns the value (#{value.inspect}) for an existing key (#{key.inspect})" do
            @hash.send(method, key).should == value
          end
        end

        it "returns nil for a non-existing key" do
          @hash.send(method, "D").should be_nil
        end
      end
    end
  end
end<commit_msg>Updated style of Hash#get spec<commit_after>require "spec_helper"
require "hamster/hash"

describe Hamster::Hash do
  [:get, :[]].each do |method|
    describe "##{method}" do
      context "with a default block" do
        let(:hash) { Hamster.hash("A" => "aye") { |key| fail }}

        context "when the key exists" do
          it "returns the value associated with the key" do
            hash.get("A").should == "aye"
          end
        end

        context "when the key does not exist" do
          let(:hash) do
            Hamster.hash("A" => "aye") do |key|
              expect(key).to eq("B")
              "bee"
            end
          end

          it "returns the value associated with the key" do
            hash.get("B").should == "bee"
          end
        end
      end

      context "with no default block" do
        let(:hash) { Hamster.hash("A" => "aye", "B" => "bee", "C" => "see", nil => "NIL") }

        [
          %w[A aye],
          %w[B bee],
          %w[C see],
          [nil, "NIL"]
        ].each do |key, value|
          it "returns the value (#{value.inspect}) for an existing key (#{key.inspect})" do
            hash.send(method, key).should == value
          end
        end

        it "returns nil for a non-existing key" do
          hash.send(method, "D").should be_nil
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.13275923932543954, 'fraction_numerical': 0.0, 'mean_word_length': 1.5601469237832875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4020303', 'n_tokens_mistral': 851, 'n_tokens_neox': 832, 'n_words': 282}