<commit_before>require 'ky/cli'
describe "cli commands" do
  let(:tmpfile_path) { "spec/support/tmpfile.yml" }
  describe "works with stdout" do
    it "decodes" do
      output = File.read('spec/support/decoded.yml')
      expect($stdout).to receive(:<<).with(output)
      KY::Cli.new.decode("spec/support/encoded.yml")
    end

    it "encodes" do
      output = File.read('spec/support/encoded.yml')
      expect($stdout).to receive(:<<).with(output)
      KY::Cli.new.encode("spec/support/decoded.yml")
    end
  end

  describe "works with files" do
    it "decodes" do
      output = File.read('spec/support/decoded.yml')
      KY::Cli.new.decode("spec/support/encoded.yml", tmpfile_path)
      expect(File.read(tmpfile_path)).to eq(output)
      `rm #{tmpfile_path}`
    end

    it "encodes" do
      output = File.read('spec/support/encoded.yml')
      KY::Cli.new.encode("spec/support/decoded.yml", tmpfile_path)
      expect(File.read(tmpfile_path)).to eq(output)
      `rm #{tmpfile_path}`
    end
  end

  describe "merges yml files" do
    it "to stdout" do
      output = File.read('spec/support/web-merged.yml')
      expect($stdout).to receive(:<<).with(output)
      KY::Cli.new.merge('spec/support/web-base.yml', 'spec/support/web-env.yml')
    end
  end

  describe "generates env section" do
    it "to stdout" do
      output = File.read('spec/support/web-env.yml')
      expect($stdout).to receive(:<<).with(output)
      KY::Cli.new.env('spec/support/decoded.yml', 'spec/support/config.yml')
    end

    it "config and secret are order independent" do
      output = File.read('spec/support/web-env.yml')
      expect($stdout).to receive(:<<).with(output)
      KY::Cli.new.env('spec/support/config.yml', 'spec/support/decoded.yml')
    end

    it "to file" do
      output = File.read('spec/support/web-env.yml')
      KY::Cli.new.env('spec/support/config.yml', 'spec/support/decoded.yml', tmpfile_path)
      expect(File.read(tmpfile_path)).to eq(output)
      `rm #{tmpfile_path}`
    end
  end

end
<commit_msg>DRY up/automate tmpfile removal<commit_after>require 'ky/cli'
describe "cli commands" do
  let(:tmpfile_path) { "spec/support/tmpfile.yml" }
  after { `rm #{tmpfile_path}` if File.exists?(tmpfile_path) }
  describe "works with stdout" do
    it "decodes" do
      output = File.read('spec/support/decoded.yml')
      expect($stdout).to receive(:<<).with(output)
      KY::Cli.new.decode("spec/support/encoded.yml")
    end

    it "encodes" do
      output = File.read('spec/support/encoded.yml')
      expect($stdout).to receive(:<<).with(output)
      KY::Cli.new.encode("spec/support/decoded.yml")
    end
  end

  describe "works with files" do
    it "decodes" do
      output = File.read('spec/support/decoded.yml')
      KY::Cli.new.decode("spec/support/encoded.yml", tmpfile_path)
      expect(File.read(tmpfile_path)).to eq(output)
    end

    it "encodes" do
      output = File.read('spec/support/encoded.yml')
      KY::Cli.new.encode("spec/support/decoded.yml", tmpfile_path)
      expect(File.read(tmpfile_path)).to eq(output)
    end
  end

  describe "merges yml files" do
    it "to stdout" do
      output = File.read('spec/support/web-merged.yml')
      expect($stdout).to receive(:<<).with(output)
      KY::Cli.new.merge('spec/support/web-base.yml', 'spec/support/web-env.yml')
    end
  end

  describe "generates env section" do
    it "to stdout" do
      output = File.read('spec/support/web-env.yml')
      expect($stdout).to receive(:<<).with(output)
      KY::Cli.new.env('spec/support/decoded.yml', 'spec/support/config.yml')
    end

    it "config and secret are order independent" do
      output = File.read('spec/support/web-env.yml')
      expect($stdout).to receive(:<<).with(output)
      KY::Cli.new.env('spec/support/config.yml', 'spec/support/decoded.yml')
    end

    it "to file" do
      output = File.read('spec/support/web-env.yml')
      KY::Cli.new.env('spec/support/config.yml', 'spec/support/decoded.yml', tmpfile_path)
      expect(File.read(tmpfile_path)).to eq(output)
    end
  end

end

{'fraction_non_alphanumeric': 0.1628305582761998, 'fraction_numerical': 0.0, 'mean_word_length': 3.1388044579533942, 'pattern_counts': {'":': 0, '<': 23, '<?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': '3056324', 'n_tokens_mistral': 1480, 'n_tokens_neox': 1392, 'n_words': 254}