<commit_before>require 'fileutils'
require 'tempfile'
require 'tmpdir'

Given /^an empty home directory$/ do
  @homedir = Dir.mktmpdir
end

And /^an empty config directory$/ do
  @configdir = Dir.mktmpdir
end

Given /^a file named "(.*?)" in the home directory$/ do |file|
  filepath = File.expand_path File.join(@homedir, file)
  @file = FileUtils.touch filepath
end

And /^"(.*?)" in the home directory should be a "(.*?)"$/ do |file, filetype|
  filepath = File.expand_path File.join(@homedir, file)
  case filetype
  when "symlink"
    File.symlink?(filepath).should be_true
  else
    raise ArgumentError
  end
end

Then /^"(.*?)" in the home directory should point to the file in the config directory$/ do |file|
  filepath = File.expand_path File.join(@homedir, file)
end

After do
  FileUtils.rmtree @homedir
  FileUtils.rmtree @configdir
end

Then /^there should be "(.*?)" files? in the config directory$/ do |number|
  count = number.to_i
  files_in_config = Dir.entries(@configdir)
  # Magic number alert! This includes ., .., and .git
  files_in_config.size.should eq count + 3 
end<commit_msg>Make sure we properly create symlinks in feature<commit_after>require 'pathname'
require 'fileutils'
require 'tempfile'
require 'tmpdir'

Given /^an empty home directory$/ do
  @homedir = Dir.mktmpdir
end

And /^an empty config directory$/ do
  @configdir = Dir.mktmpdir
end

Given /^a file named "(.*?)" in the home directory$/ do |file|
  filepath = File.expand_path File.join(@homedir, file)
  @file = FileUtils.touch filepath
end

And /^"(.*?)" in the home directory should be a "(.*?)"$/ do |file, filetype|
  filepath = File.expand_path File.join(@homedir, file)
  case filetype
    when 'symlink'
      File.symlink?(filepath).should be_true
    else
      raise ArgumentError
  end
end

Then /^"(.*?)" in the home directory should point to the file in the config directory$/ do |file|
  destpath = File.expand_path File.join(@configdir, file)
  orig_dir = Dir.pwd
  Dir.chdir @configdir
  symlink_destination = Pathname.new(file).realpath.to_s
  Dir.chdir orig_dir
  symlink_destination.should match Regexp.escape(destpath)

end

After do
  FileUtils.rmtree @homedir
  FileUtils.rmtree @configdir
end

Then /^there should be "(.*?)" files? in the config directory$/ do |number|
  count = number.to_i
  files_in_config = Dir.entries(@configdir)
  # Magic number alert! This includes ., .., and .git
  files_in_config.size.should eq count + 3
end
{'fraction_non_alphanumeric': 0.11834078893859293, 'fraction_numerical': 0.0008133387555917039, 'mean_word_length': 3.929859719438878, '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': '1360576', 'n_tokens_mistral': 850, 'n_tokens_neox': 830, 'n_words': 265}