<commit_before>require 'spec_helper'
require 'delegate'

module RSpec
  module Matchers
    describe "RSpec::Matchers.configuration" do
      it 'returns a memoized configuration instance' do
        RSpec::Matchers.configuration.should be_a(RSpec::Matchers::Configuration)
        RSpec::Matchers.configuration.should be(RSpec::Matchers.configuration)
      end
    end

    describe Configuration do
      let(:config) { Configuration.new }

      describe "#backtrace_formatter" do
        let(:original_backtrace) { %w[ clean-me/a.rb other/file.rb clean-me/b.rb ] }
        let(:cleaned_backtrace)  { %w[ other/file.rb ] }

        let(:formatted_backtrace) do
          config.backtrace_formatter.format_backtrace(original_backtrace)
        end

        before do
          RSpec.configuration.stub(:backtrace_clean_patterns) { [/clean-me/] }
        end

        it "defaults to rspec-core's backtrace formatter when rspec-core is loaded" do
          expect(config.backtrace_formatter).to be(RSpec::Core::BacktraceFormatter)
          expect(formatted_backtrace).to eq(cleaned_backtrace)
        end

        it "defaults to a null formatter when rspec-core is not loaded" do
          stub_const("RSpec::Core", nil) # so the formatter module is not loaded
          expect(formatted_backtrace).to eq(original_backtrace)
        end

        it "can be set to another backtrace formatter" do
          config.backtrace_formatter = stub(:format_backtrace => ['a'])
          expect(formatted_backtrace).to eq(['a'])
        end
      end

      context 'on an interpreter that does not provide BasicObject', :unless => defined?(::BasicObject) do
        before { RSpec::Expectations::Syntax.disable_should(Delegator) }

        let(:klass) do
          Class.new(SimpleDelegator) do
            def delegated?; true; end
          end
        end

        let(:instance) { klass.new(Object.new) }

        it 'provides a means to manually add it Delegator' do
          instance.should_not respond_to(:delegated?) # because #should is being delegated...
          config.add_should_and_should_not_to Delegator
          instance.should respond_to(:delegated?) # now it should work!
        end<commit_msg>Use `hide_const` at a place where we really just want to hide a constant.<commit_after>require 'spec_helper'
require 'delegate'

module RSpec
  module Matchers
    describe "RSpec::Matchers.configuration" do
      it 'returns a memoized configuration instance' do
        RSpec::Matchers.configuration.should be_a(RSpec::Matchers::Configuration)
        RSpec::Matchers.configuration.should be(RSpec::Matchers.configuration)
      end
    end

    describe Configuration do
      let(:config) { Configuration.new }

      describe "#backtrace_formatter" do
        let(:original_backtrace) { %w[ clean-me/a.rb other/file.rb clean-me/b.rb ] }
        let(:cleaned_backtrace)  { %w[ other/file.rb ] }

        let(:formatted_backtrace) do
          config.backtrace_formatter.format_backtrace(original_backtrace)
        end

        before do
          RSpec.configuration.stub(:backtrace_clean_patterns) { [/clean-me/] }
        end

        it "defaults to rspec-core's backtrace formatter when rspec-core is loaded" do
          expect(config.backtrace_formatter).to be(RSpec::Core::BacktraceFormatter)
          expect(formatted_backtrace).to eq(cleaned_backtrace)
        end

        it "defaults to a null formatter when rspec-core is not loaded" do
          hide_const("RSpec::Core::BacktraceFormatter")
          expect(formatted_backtrace).to eq(original_backtrace)
        end

        it "can be set to another backtrace formatter" do
          config.backtrace_formatter = stub(:format_backtrace => ['a'])
          expect(formatted_backtrace).to eq(['a'])
        end
      end

      context 'on an interpreter that does not provide BasicObject', :unless => defined?(::BasicObject) do
        before { RSpec::Expectations::Syntax.disable_should(Delegator) }

        let(:klass) do
          Class.new(SimpleDelegator) do
            def delegated?; true; end
          end
        end

        let(:instance) { klass.new(Object.new) }

        it 'provides a means to manually add it Delegator' do
          instance.should_not respond_to(:delegated?) # because #should is being delegated...
          config.add_should_and_should_not_to Delegator
          instance.should respond_to(:delegated?) # now it should work!
        end
{'fraction_non_alphanumeric': 0.09172460192868356, 'fraction_numerical': 0.0, 'mean_word_length': 2.798977853492334, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4999803', 'n_tokens_mistral': 1273, 'n_tokens_neox': 1251, 'n_words': 318}