<commit_before># encoding: utf-8
require 'spec_helper'

class SelfObserver
  def self.cache
    @cache ||= []
  end

  def initialize
    self.class.cache << self
  end
end

module RSpec::Core
  RSpec.describe ExampleGroup do
    it_behaves_like "metadata hash builder" do
      def metadata_hash(*args)
        group = ExampleGroup.describe('example description', *args)
        group.metadata
      end
    end

    context "when RSpec.configuration.format_docstrings is set to a block" do
      it "formats the description with that block" do
        RSpec.configuration.format_docstrings { |s| s.upcase }
        group = ExampleGroup.describe(' an example ')
        expect(group.description).to eq(' AN EXAMPLE ')
      end
    end

    it 'does not treat the first argument as a metadata key even if it is a symbol' do
      group = ExampleGroup.describe(:symbol)
      expect(group.metadata).not_to include(:symbol)
    end

    it 'treats the first argument as part of the description when it is a symbol' do
      group = ExampleGroup.describe(:symbol)
      expect(group.description).to eq("symbol")
    end

    describe "constant naming" do
      RSpec::Matchers.define :have_class_const do |class_name|
        match do |group|
          group.name == "RSpec::ExampleGroups::#{class_name}" &&
          group == class_name.split('::').inject(RSpec::ExampleGroups) do |mod, name|
            mod.const_get(name)
          end
        end
      end

      it 'gives groups friendly human readable class names' do
        stub_const("MyGem::Klass", Class.new)
        parent = ExampleGroup.describe(MyGem::Klass)
        expect(parent).to have_class_const("MyGemKlass")
      end

      it 'nests constants to match the group nesting' do
        grandparent = ExampleGroup.describe("The grandparent")
        parent      = grandparent.describe("the parent")
        child       = parent.describe("the child")

        expect(parent).to have_class_const("TheGrandparent::TheParent")
        expect(child).to have_class_const("TheGrandparent::TheParent::TheChild")
      end

      it 'removes non-ascii characters from the const name since some rubies barf on that' do
        group = ExampleGroup.describe("A chinese character: 们")
        expect(group).to have_class_const("AChineseCharacter")
      end

      it 'prefixes the const name with "Nested" if needed to make a valid const' do
        expect {
          ExampleGroup.const_set("1B", Object.new)
        }.to raise_error(NameError)

        group = ExampleGroup.describe("1B")
        expect(group).to have_class_const("Nested1B")
      end

      it 'does not warn when defining a Config example group (since RbConfig triggers warnings when Config is referenced)' do
        expect { ExampleGroup.describe("Config") }.not_to output.to_stderr
      end

      it 'disambiguates name collisions by appending a number' do
        groups = 10.times.map { ExampleGroup.describe("Collision") }
        expect(groups[0]).to have_class_const("Collision")
        expect(groups[1]).to have_class_const("Collision_2")
        expect(groups[8]).to have_class_const("Collision_9")

        if RUBY_VERSION.to_f > 1.8 && !(defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx')
          # on 1.8.7, rbx "Collision_9".next => "Collisioo_0"
          expect(groups[9]).to have_class_const("Collision_10")
        end
      end<commit_msg>Add an additional spec for the first from #1580.<commit_after># encoding: utf-8
require 'spec_helper'

class SelfObserver
  def self.cache
    @cache ||= []
  end

  def initialize
    self.class.cache << self
  end
end

module RSpec::Core
  RSpec.describe ExampleGroup do
    it_behaves_like "metadata hash builder" do
      def metadata_hash(*args)
        group = ExampleGroup.describe('example description', *args)
        group.metadata
      end
    end

    context "when RSpec.configuration.format_docstrings is set to a block" do
      it "formats the description with that block" do
        RSpec.configuration.format_docstrings { |s| s.upcase }
        group = ExampleGroup.describe(' an example ')
        expect(group.description).to eq(' AN EXAMPLE ')
      end
    end

    it 'does not treat the first argument as a metadata key even if it is a symbol' do
      group = ExampleGroup.describe(:symbol)
      expect(group.metadata).not_to include(:symbol)
    end

    it 'treats the first argument as part of the description when it is a symbol' do
      group = ExampleGroup.describe(:symbol)
      expect(group.description).to eq("symbol")
    end

    describe "constant naming" do
      RSpec::Matchers.define :have_class_const do |class_name|
        match do |group|
          group.name == "RSpec::ExampleGroups::#{class_name}" &&
          group == class_name.split('::').inject(RSpec::ExampleGroups) do |mod, name|
            mod.const_get(name)
          end
        end
      end

      it 'gives groups friendly human readable class names' do
        stub_const("MyGem::Klass", Class.new)
        parent = ExampleGroup.describe(MyGem::Klass)
        expect(parent).to have_class_const("MyGemKlass")
      end

      it 'nests constants to match the group nesting' do
        grandparent = ExampleGroup.describe("The grandparent")
        parent      = grandparent.describe("the parent")
        child       = parent.describe("the child")

        expect(parent).to have_class_const("TheGrandparent::TheParent")
        expect(child).to have_class_const("TheGrandparent::TheParent::TheChild")
      end

      it 'removes non-ascii characters from the const name since some rubies barf on that' do
        group = ExampleGroup.describe("A chinese character: 们")
        expect(group).to have_class_const("AChineseCharacter")
      end

      it 'prefixes the const name with "Nested" if needed to make a valid const' do
        expect {
          ExampleGroup.const_set("1B", Object.new)
        }.to raise_error(NameError)

        group = ExampleGroup.describe("1B")
        expect(group).to have_class_const("Nested1B")
      end

      it 'does not warn when defining a Config example group (since RbConfig triggers warnings when Config is referenced)' do
        expect { ExampleGroup.describe("Config") }.not_to output.to_stderr
      end

      it 'ignores top level constants that have the same name' do
        parent = RSpec.describe("Some Parent Group")
        child  = parent.describe("Hash")
        # This would be `SomeParentGroup::Hash_2` if we didn't ignore the top level `Hash`
        expect(child).to have_class_const("SomeParentGroup::Hash")
      end

      it 'disambiguates name collisions by appending a number' do
        groups = 10.times.map { ExampleGroup.describe("Collision") }
        expect(groups[0]).to have_class_const("Collision")
        expect(groups[1]).to have_class_const("Collision_2")
        expect(groups[8]).to have_class_const("Collision_9")

        if RUBY_VERSION.to_f > 1.8 && !(defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx')
          # on 1.8.7, rbx "Collision_9".next => "Collisioo_0"
          expect(groups[9]).to have_class_const("Collision_10")
        end
      end
{'fraction_non_alphanumeric': 0.09815177821338561, 'fraction_numerical': 0.006580789694763372, 'mean_word_length': 2.8862894450489662, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2349452', 'n_tokens_mistral': 2127, 'n_tokens_neox': 2026, 'n_words': 591}