<commit_before>require 'omnibus'
require 'fauxhai'

module Omnibus
  module RSpec
    SPEC_DATA = File.expand_path(File.join(File.dirname(__FILE__), 'data'))

    def software_path(name)
      File.join(SPEC_DATA, 'software', "#{name}.rb")
    end

    def overrides_path(name)
      File.join(SPEC_DATA, 'overrides', "#{name}.overrides")
    end

    def project_path(name)
      File.join(SPEC_DATA, 'projects', "#{name}.rb")
    end

    def fixtures_path
      File.expand_path('../fixtures', __FILE__)
    end

    def tmp_path
      File.expand_path('../../tmp', __FILE__)
    end

    #
    # Stub Ohai with the given data.
    #
    # @param [Hash] data
    #
    def stub_ohai(data = {})
      system = ::Ohai::System.new
      system.data = Mash.new(data)

      Ohai.stub(:ohai).and_return(system)
    end

    #
    # Grab the result of the log command. Since Omnibus uses the block form of
    # the logger, this method handles both types of logging.
    #
    # @example
    #   output = capture_logging { some_command }
    #   expect(output).to include('whatever')
    #
    def capture_logging
      Omnibus.log.level = :debug
      original = $stdout
      $stdout = fake = StringIO.new

      [:fatal, :error, :warn, :info, :debug].each do |level|
        Omnibus.log.stub(level) do |args, &b|
          if b
            fake.puts(b.call)
          else
            fake.puts(args.join)
          end
        end
      end

      yield

      fake.string
    ensure
      Omnibus.log_level = :unknown
      $stdout = original
    end
  end
end

def windows?
  !!(RUBY_PLATFORM =~ /mswin|mingw|windows/)
end

def mac?
  !!(RUBY_PLATFORM =~ /darwin/)
end

RSpec.configure do |config|
  config.include Omnibus::RSpec
  config.filter_run focus: true
  config.run_all_when_everything_filtered = true
  config.treat_symbols_as_metadata_keys_with_true_values = true

  config.filter_run_excluding windows_only: true unless windows?
  config.filter_run_excluding mac_only: true unless mac?

  config.before(:each) do
    # Suppress logging
    Omnibus.log_level = :unknown

    # Clear the tmp_path on each run
    FileUtils.rm_rf(tmp_path)
    FileUtils.mkdir_p(tmp_path)
  end

  # Force the expect syntax
  config.expect_with :rspec do |c|
    c.syntax = :expect
  end
end<commit_msg>Run specs in a random order<commit_after>require 'omnibus'
require 'fauxhai'

module Omnibus
  module RSpec
    SPEC_DATA = File.expand_path(File.join(File.dirname(__FILE__), 'data'))

    def software_path(name)
      File.join(SPEC_DATA, 'software', "#{name}.rb")
    end

    def overrides_path(name)
      File.join(SPEC_DATA, 'overrides', "#{name}.overrides")
    end

    def project_path(name)
      File.join(SPEC_DATA, 'projects', "#{name}.rb")
    end

    def fixtures_path
      File.expand_path('../fixtures', __FILE__)
    end

    def tmp_path
      File.expand_path('../../tmp', __FILE__)
    end

    #
    # Stub Ohai with the given data.
    #
    # @param [Hash] data
    #
    def stub_ohai(data = {})
      system = ::Ohai::System.new
      system.data = Mash.new(data)

      Ohai.stub(:ohai).and_return(system)
    end

    #
    # Grab the result of the log command. Since Omnibus uses the block form of
    # the logger, this method handles both types of logging.
    #
    # @example
    #   output = capture_logging { some_command }
    #   expect(output).to include('whatever')
    #
    def capture_logging
      Omnibus.log.level = :debug
      original = $stdout
      $stdout = fake = StringIO.new

      [:fatal, :error, :warn, :info, :debug].each do |level|
        Omnibus.log.stub(level) do |args, &b|
          if b
            fake.puts(b.call)
          else
            fake.puts(args.join)
          end
        end
      end

      yield

      fake.string
    ensure
      Omnibus.log_level = :unknown
      $stdout = original
    end
  end
end

def windows?
  !!(RUBY_PLATFORM =~ /mswin|mingw|windows/)
end

def mac?
  !!(RUBY_PLATFORM =~ /darwin/)
end

RSpec.configure do |config|
  config.include Omnibus::RSpec
  config.filter_run focus: true
  config.run_all_when_everything_filtered = true
  config.treat_symbols_as_metadata_keys_with_true_values = true

  config.filter_run_excluding windows_only: true unless windows?
  config.filter_run_excluding mac_only: true unless mac?

  config.before(:each) do
    # Suppress logging
    Omnibus.log_level = :unknown

    # Clear the tmp_path on each run
    FileUtils.rm_rf(tmp_path)
    FileUtils.mkdir_p(tmp_path)
  end

  # Force the expect syntax
  config.expect_with :rspec do |c|
    c.syntax = :expect
  end

  # Run specs in a random order
  config.order = 'random'
end
{'fraction_non_alphanumeric': 0.1068751338616406, 'fraction_numerical': 0.0, 'mean_word_length': 2.58678955453149, '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': '1505940', 'n_tokens_mistral': 1645, 'n_tokens_neox': 1567, 'n_words': 376}