<commit_before>shared_examples 'a class with change_key method' do
  describe :change_keys do
    it_behaves_like 'a mnethod that is able to change keys', :change_keys

    it 'does not affects the original hash' do
      original = { 'a' => 1, b: 2, c: { d: 3, e: 4 }, f: [{ g: 5 }, { h: 6 }] }

      expect do
        original.change_keys(recursive: true) { |k| "foo_#{k}" }
      end.not_to change { original }
    end
  end

  describe :change_keys! do
    it_behaves_like 'a mnethod that is able to change keys', :change_keys!

    it 'affects the original hash' do
      original = { 'a' => 1, b: 2, c: { d: 3, e: 4 }, f: [{ g: 5 }, { h: 6 }] }

      expect do
        original.change_keys!(recursive: true) { |k| "foo_#{k}" }
      end.to change { original }
    end
  end
end

shared_examples 'a mnethod that is able to change keys' do |method|
  it 'accepts block to change the keys' do
    expect({ 'a' => 1, b: 2 }.public_send(method) { |k| "foo_#{k}" }).to eq('foo_a' => 1, 'foo_b' => 2)
  end

  it 'accepts block to change the keys' do
    expect({ a: 1, 'b' => 2 }.public_send(method) { |k| "foo_#{k}".to_sym }).to eq(foo_a: 1, foo_b: 2)
  end

  context 'with recursive hash' do
    let(:hash) { { 'a' => 1, b:  { c: 3, 'd' => 4 } } }
    let(:result) { hash.public_send(method, options) { |k| "foo_#{k}" } }
    let(:expected) do
      { 'foo_a' => 1, 'foo_b' =>  { 'foo_c' => 3, 'foo_d' => 4 } }
    end

    context 'when no options are given' do
      let(:options) { {} }

      it 'applies the block recursively' do
        expect(result).to eq(expected)
      end
    end

    context 'when options are given' do
      let(:options) { { recursive: recursive } }<commit_msg>use common hash for change original spec<commit_after>shared_examples 'a class with change_key method' do
  let(:hash) do
    { 'a' => 1, b: 2, c: { d: 3, e: 4 }, f: [{ g: 5 }, { h: 6 }] }
  end

  describe :change_keys do

    it_behaves_like 'a mnethod that is able to change keys', :change_keys
    it 'does not affects the original hash' do
      expect do
        hash.change_keys(recursive: true) { |k| "foo_#{k}" }
      end.not_to change { hash }
    end
  end

  describe :change_keys! do
    it_behaves_like 'a mnethod that is able to change keys', :change_keys!

    it 'affects the original hash' do
      expect do
        hash.change_keys!(recursive: true) { |k| "foo_#{k}" }
      end.to change { hash }
    end
  end
end

shared_examples 'a mnethod that is able to change keys' do |method|
  it 'accepts block to change the keys' do
    expect({ 'a' => 1, b: 2 }.public_send(method) { |k| "foo_#{k}" }).to eq('foo_a' => 1, 'foo_b' => 2)
  end

  it 'accepts block to change the keys' do
    expect({ a: 1, 'b' => 2 }.public_send(method) { |k| "foo_#{k}".to_sym }).to eq(foo_a: 1, foo_b: 2)
  end

  context 'with recursive hash' do
    let(:hash) { { 'a' => 1, b:  { c: 3, 'd' => 4 } } }
    let(:result) { hash.public_send(method, options) { |k| "foo_#{k}" } }
    let(:expected) do
      { 'foo_a' => 1, 'foo_b' =>  { 'foo_c' => 3, 'foo_d' => 4 } }
    end

    context 'when no options are given' do
      let(:options) { {} }

      it 'applies the block recursively' do
        expect(result).to eq(expected)
      end
    end

    context 'when options are given' do
      let(:options) { { recursive: recursive } }
{'fraction_non_alphanumeric': 0.1550224887556222, 'fraction_numerical': 0.013793103448275862, 'mean_word_length': 2.6984478935698446, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, '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': '3625304', 'n_tokens_mistral': 1300, 'n_tokens_neox': 1226, 'n_words': 413}