<commit_before>require 'spec_helper'
require 'acls'

RSpec.describe ACLS::Loader do
  context '#auto' do
    def works?(modules)
      modules.each do |name|
        expect { Object.const_get(name) }.not_to raise_error
        expect(Object.const_get(name).works?).to be_truthy
      end
    end

    def lib_modules
      %w(One Two Sub::Three Sub::Four FIVE Six SevenEight Sub::CamelCase::NineTen)
    end

    def lib_root_modules
      %w(Root::One Root::Two Root::Sub::Three Root::Sub::Four Root::Sub::Five Root::Sub::Six)
    end

    def lib_foo_modules
      %w(Bar::One Bar::Two Bar::Sub::Three Bar::Sub::Four Bar::Sub::Five Bar::Sub::Six)
    end

    def spec_path(dir)
      "#{Dir.pwd}/spec/#{dir}"
    end

    context 'without a root namespace' do
      it do
        ACLS::Loader.auto(spec_path("lib"))
        works?(lib_modules)
      end
    end

    context 'with an implicit root namespace' do
      it do
        ACLS::Loader.auto(spec_path("lib/root"), root_ns: true)
        works?(lib_root_modules)
      end
    end

    context 'with a custom root namespace' do
      it do
        ACLS::Loader.auto(spec_path("lib/foo"), root_ns: "Bar")
        works?(lib_foo_modules)
      end
    end
  end
end<commit_msg>Improve specs with a custom matcher<commit_after>require 'spec_helper'
require 'acls'

def spec_path(dir)
  "#{Dir.pwd}/spec/#{dir}"
end

def autoload_path(path, opts)
  ACLS::Loader.auto(spec_path(path), opts)
end

RSpec::Matchers.define :setup_autoloading_for do |modules|
  description do
    "setup autoloading"
  end

  match do |actual|
    begin
      verify(modules)
    rescue
      false
    end
  end

  def verify(modules)
    modules.each do |name|
      Object.const_get(name).works? or raise "Incorrect module loaded"
    end
  end
end

RSpec.describe ACLS::Loader do
  context '#auto' do
    def lib_modules
      %w(One Two Sub::Three Sub::Four FIVE Six SevenEight Sub::CamelCase::NineTen)
    end

    def lib_root_modules
      %w(Root::One Root::Two Root::Sub::Three Root::Sub::Four Root::Sub::Five Root::Sub::Six)
    end

    def lib_foo_modules
      %w(Bar::One Bar::Two Bar::Sub::Three Bar::Sub::Four Bar::Sub::Five Bar::Sub::Six)
    end

    def expect_autoloading_for(path, opts, modules)
      expect(autoload_path(path, opts)).to setup_autoloading_for(modules)
    end

    context 'without a root namespace' do
      it { expect_autoloading_for("lib", {}, lib_modules) }
    end

    context 'with an implicit root namespace' do
      it { expect_autoloading_for("lib/root", {root_ns: true}, lib_root_modules) }
    end

    context 'with a custom root namespace' do
      it { expect_autoloading_for("lib/foo", {root_ns: "Bar"}, lib_foo_modules) }
    end
  end
end
{'fraction_non_alphanumeric': 0.11891694109037687, 'fraction_numerical': 0.0, 'mean_word_length': 3.206153846153846, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '185500', 'n_tokens_mistral': 961, 'n_tokens_neox': 925, 'n_words': 231}