<commit_before>require 'rubygems'
require 'bundler/setup'

require 'thebes' # and any other gems you need

FileUtils.mkdir_p 'tmp'

Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each {|f| require f}

RSpec.configure do |config|
  config.mock_with :mocha
  config.use_transactional_fixtures = true
  config.before :all do
    config = YAML.load(ERB.new(IO.read(File.join(File.dirname(__FILE__), 'support/database.yml'))).result)['test']
    generator = Thebes::ConfigWriter.new(File.join(File.dirname(__FILE__), 'support'), 'test.sphinx.conf')
    generator.build File.join(File.dirname(__FILE__), 'support/test.sphinx.conf'), config

    riddle_config = Riddle::Configuration.new
    riddle_config.searchd.pid_file = 'tmp/searchd.pid'
    riddle_config.searchd.log = 'tmp/searchd.log'
    @sphinx = Riddle::Controller.new \
      riddle_config,
      File.join(File.dirname(__FILE__), 'support/test.sphinx.conf')
    @sphinx.start
    @sphinx.index
  end
  config.after :all do
    @sphinx.stop
  end
end

RSpec::Matchers.define :define_constant do |expected|
  match { |actual| actual.const_defined?(expected) }
end<commit_msg>Clean up some of this searchd management madness<commit_after>require 'rubygems'
require 'bundler/setup'

require 'thebes' # and any other gems you need

FileUtils.mkdir_p 'tmp'

Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each {|f| require f}

RSpec.configure do |config|
  config.mock_with :mocha
  config.use_transactional_fixtures = true
  config.before :all do

    # Fetch a database configuration.
    #
    db_config = YAML.load( ERB.new( IO.read(
      File.join(File.dirname(__FILE__), 'support/database.yml')
    ) ).result )['test']

    # Write a sphinx configuation for test mode.
    #
    generator = Thebes::ConfigWriter.new \
      File.join(File.dirname(__FILE__), 'support'),
      'test.sphinx.conf'
    generator.build \
      File.join(File.dirname(__FILE__), 'support/test.sphinx.conf'),
      db_config

    # Give Riddle a dummy configuration so we can use it to
    # control searchd.
    #
    r_config = Riddle::Configuration.new
    r_config.searchd.pid_file = 'tmp/searchd.pid'
    r_config.searchd.log = 'tmp/searchd.log'

    # Create a Riddle controller.
    #
    @sphinx = Riddle::Controller.new \
      r_config,
      File.join(File.dirname(__FILE__), 'support/test.sphinx.conf')

    # Build an initial index.
    #
    @sphinx.index

    # Start searchd.
    #
    @sphinx.start

  end
  config.after :all do

    # Stop searchd after specs run.
    #
    @sphinx.stop

  end
end

RSpec::Matchers.define :define_constant do |expected|
  match { |actual| actual.const_defined?(expected) }
end
{'fraction_non_alphanumeric': 0.1303538175046555, 'fraction_numerical': 0.0, 'mean_word_length': 3.568027210884354, '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': '2715205', 'n_tokens_mistral': 943, 'n_tokens_neox': 921, 'n_words': 187}