<commit_before>require 'spork'

Spork.prefork do
  ENV["RAILS_ENV"] ||= 'test'

  require 'rails/application'
  # Prevent Spork from caching the routes.
  Spork.trap_method(Rails::Application::RoutesReloader, :reload!)
  # Prevent Spork from caching Popolo classes (see below).
  Spork.trap_method(Rails::Application, :eager_load!)

  require File.expand_path("../dummy/config/environment.rb",  __FILE__)
  require 'rspec/rails'

  # Requires supporting ruby files with custom matchers and macros, etc,
  # in spec/support/ and its subdirectories.
  Dir[File.expand_path("../support/**/*.rb", __FILE__)].each {|f| require f}

  # Prevent Spork from caching Popolo classes (see above).
  Rails.application.railties.all do |railtie|
    unless railtie.respond_to?(:engine_name) && railtie.engine_name == 'popolo'
      railtie.eager_load!
    end
  end

  # Create non-Popolo indexes.
  Rails.application.railties.engines.each do |engine|
    unless engine.engine_name == 'popolo'
      engine.paths["app/models"].expanded.each do |path|
        Rails::Mongoid.create_indexes("#{path}/**/*.rb")
      end
    end
  end

  require 'database_cleaner'
  require 'factory_girl_rails'
  require 'mongoid-rspec'

  RSpec.configure do |config|
    config.include Mongoid::Matchers

    config.mock_with :rspec

    config.after(:each) do
      DatabaseCleaner.clean
    end

    # http://railscasts.com/episodes/285-spork
    config.treat_symbols_as_metadata_keys_with_true_values = true
    config.run_all_when_everything_filtered = true
    config.filter_run focus: true
  end
end

Spork.each_run do
  # DatabaseCleaner will not truncate system.indexes between tests, but it
  # should be truncated before running the full test suite.
  Mongoid::Sessions.default.drop

  # It's now okay to load Popolo.
  Rails.application.railties.engines.each do |engine|
    if engine.engine_name == 'popolo'
      engine.eager_load!
    end
  end

  # Create Popolo indexes.
  Rails.application.railties.engines.each do |engine|
    if engine.engine_name == 'popolo'
      engine.paths["app/models"].expanded.each do |path|
        Rails::Mongoid.create_indexes("#{path}/**/*.rb")
      end
    end
  end

  # Create dummy indexes.
  Rails::Mongoid.create_indexes(File.expand_path("../dummy/app/models/**/*.rb", __FILE__))

  # @todo I18n.backend.reload!
  FactoryGirl.reload
end<commit_msg>fix factory_girl_rails/spork issue<commit_after>require 'spork'

Spork.prefork do
  ENV["RAILS_ENV"] ||= 'test'

  require 'rails/application'
  # Prevent Spork from caching the routes.
  Spork.trap_method(Rails::Application::RoutesReloader, :reload!)
  # Prevent Spork from caching Popolo classes (see below).
  Spork.trap_method(Rails::Application, :eager_load!)

  require File.expand_path("../dummy/config/environment.rb",  __FILE__)
  require 'rspec/rails'

  # Requires supporting ruby files with custom matchers and macros, etc,
  # in spec/support/ and its subdirectories.
  Dir[File.expand_path("../support/**/*.rb", __FILE__)].each {|f| require f}

  # Prevent Spork from caching Popolo classes (see above).
  Rails.application.railties.all do |railtie|
    unless railtie.respond_to?(:engine_name) && railtie.engine_name == 'popolo'
      railtie.eager_load!
    end
  end

  # Create non-Popolo indexes.
  Rails.application.railties.engines.each do |engine|
    unless engine.engine_name == 'popolo'
      engine.paths["app/models"].expanded.each do |path|
        Rails::Mongoid.create_indexes("#{path}/**/*.rb")
      end
    end
  end

  require 'database_cleaner'
  require 'mongoid-rspec'

  RSpec.configure do |config|
    config.include Mongoid::Matchers

    config.mock_with :rspec

    config.after(:each) do
      DatabaseCleaner.clean
    end

    # http://railscasts.com/episodes/285-spork
    config.treat_symbols_as_metadata_keys_with_true_values = true
    config.run_all_when_everything_filtered = true
    config.filter_run focus: true
  end
end

Spork.each_run do
  # DatabaseCleaner will not truncate system.indexes between tests, but it
  # should be truncated before running the full test suite.
  Mongoid::Sessions.default.drop

  # It's now okay to load Popolo.
  Rails.application.railties.engines.each do |engine|
    if engine.engine_name == 'popolo'
      engine.eager_load!
    end
  end

  # Create Popolo indexes.
  Rails.application.railties.engines.each do |engine|
    if engine.engine_name == 'popolo'
      engine.paths["app/models"].expanded.each do |path|
        Rails::Mongoid.create_indexes("#{path}/**/*.rb")
      end
    end
  end

  # Create dummy indexes.
  Rails::Mongoid.create_indexes(File.expand_path("../dummy/app/models/**/*.rb", __FILE__))

  # @todo I18n.backend.reload!

  require 'factory_girl_rails'
  FactoryGirl.reload
end
{'fraction_non_alphanumeric': 0.11691855583543241, 'fraction_numerical': 0.0020990764063811922, 'mean_word_length': 3.7038499506416582, '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': '4583571', 'n_tokens_mistral': 1668, 'n_tokens_neox': 1589, 'n_words': 347}