<commit_before># frozen_string_literal: true

require 'simplecov'
SimpleCov.start

require 'minitest/autorun'
require 'usesthis'
require 'json'
require 'yaml'

def test_site
  @test_site ||= UsesThis::Site.new(test_configuration)
end

def test_configuration
  @test_configuration ||= Dimples::Configuration.new(
    'source_path' => File.join(__dir__, 'source'),
    'destination_path' => temp_site_path,
    'class_overrides' => {
      'site' => 'UsesThis::Site',
      'post' => 'UsesThis::Interview'
    }
  )
end

def temp_site_path
  File.join(File::SEPARATOR, 'tmp', "usesthis-#{Time.new.to_i}")
end

def test_interview
  @test_interview ||= read_json_fixture('interview')
end

def fixture_path(name)
  File.join(__dir__, 'fixtures', name)
end

def read_json_fixture(name)
  JSON.parse(File.read(fixture_path("#{name}.json")))
end

def read_yaml_fixture(name)
  YAML.load_file(fixture_path("#{name}.yml"))
end

def read_api_file(path = nil)
  path = File.join(test_site.output_paths[:site], 'api', path, 'index.json')
  JSON.parse(File.read(path))
end<commit_msg>Require little-fixtures, remove the old test site and interview method, add a match_api_fixture method.<commit_after># frozen_string_literal: true

require 'simplecov'
SimpleCov.start

require 'minitest/autorun'
require 'usesthis'
require 'little-fixtures'
require 'yaml'

def test_configuration
  Dimples::Configuration.new(
    'source_path' => File.join(__dir__, 'source'),
    'destination_path' => File.join(
      File::SEPARATOR, 'tmp', "usesthis-#{Time.new.to_i}"
    ),
    'class_overrides' => {
      'site' => 'UsesThis::Site',
      'post' => 'UsesThis::Interview'
    }
  )
end

def fixtures
  @fixtures ||= LittleFixtures.load(File.join(__dir__, 'fixtures'))
end

def match_api_fixture(fixture)
  expected_output = JSON.parse(fixtures[fixture])

  parts = fixture.split('.')
  parts.delete('index') if parts.last == 'index'

  path = File.join(
    @site.output_paths[:site],
    parts,
    'index.json'
  )

  File.exist?(path).must_equal(true)
  JSON.parse(File.read(path)).must_equal(expected_output)
end
{'fraction_non_alphanumeric': 0.14961759082217974, 'fraction_numerical': 0.0, 'mean_word_length': 5.0491329479768785, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '4504904', 'n_tokens_mistral': 753, 'n_tokens_neox': 760, 'n_words': 136}