<commit_before>require "statesman"
require "sqlite3"
require "active_record"
require "support/active_record"

RSpec.configure do |config|
  config.expect_with :rspec do |c|
    c.syntax = :expect
  end

  config.order = 'random'

  config.before(:each) do
    # Connect to & cleanup test database
    ActiveRecord::Base.establish_connection(adapter: "sqlite3",
                                            database: DB.to_s)

    %w(my_models my_model_transitions).each do |table_name|
      sql = "DROP TABLE IF EXISTS #{table_name};"
      ActiveRecord::Base.connection.execute(sql)
    end

    def prepare_model_table
      silence_stream(STDOUT) do
        CreateMyActiveRecordModelMigration.migrate(:up)
      end
    end

    def prepare_transitions_table<commit_msg>Fail specs early if mongo is not running and filter is not set<commit_after>require "statesman"
require "sqlite3"
require "active_record"
require "support/active_record"
require "mongoid"

RSpec.configure do |config|
  config.expect_with :rspec do |c|
    c.syntax = :expect
  end

  config.order = "random"

  # Try a mongo connection at the start of the suite and raise if it fails
  begin
    Mongoid.configure do |config|
      config.connect_to("statesman_test")
      config.sessions["default"]["options"]["max_retries"] = 2
    end
    # Attempting a mongo operation will triger 2 retries then trow an exception
    # if mongo is not running.
    Mongoid.purge! unless config.exclusion_filter[:mongo]
  rescue Moped::Errors::ConnectionFailure => error
    puts "The spec suite requires MongoDB to be installed and running locally"
    puts "Mongo dependent specs can be filtered with rspec --tag '~mongo'"
    raise(error)
  end

  config.before(:each) do
    # Connect to & cleanup test database
    ActiveRecord::Base.establish_connection(adapter: "sqlite3",
                                            database: DB.to_s)

    %w(my_models my_model_transitions).each do |table_name|
      sql = "DROP TABLE IF EXISTS #{table_name};"
      ActiveRecord::Base.connection.execute(sql)
    end

    def prepare_model_table
      silence_stream(STDOUT) do
        CreateMyActiveRecordModelMigration.migrate(:up)
      end
    end

    def prepare_transitions_table
{'fraction_non_alphanumeric': 0.08344489067380634, 'fraction_numerical': 0.002677376171352075, 'mean_word_length': 3.2142857142857144, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '725343', 'n_tokens_mistral': 673, 'n_tokens_neox': 662, 'n_words': 188}