<commit_before>require "stringio"

RSpec.describe Vmdb::Loggers do
  let(:log_file_name) { "foo.log" }
  let(:log_file_path) { Rails.root.join("log", log_file_name) }

  after do
    log_file_path.delete if log_file_path.exist?
  end

  def in_container_env(example)
    old_env = ENV.delete('CONTAINER')
    ENV['CONTAINER'] = 'true'

    example.run
  ensure
    ENV['CONTAINER'] = old_env
  end

  describe ".create_logger" do
    shared_examples "has basic logging functionality" do
      let(:log_file) { log_file_name }

      subject { described_class.create_logger(log_file) }

      let(:container_log) { subject.instance_variable_get(:@broadcast_logger) }

      before do
        # Hide the container logger output to STDOUT
        allow(container_log.logdev).to receive(:write) if container_log
      end

      it "responds to #<<" do
        expect(subject).to respond_to(:<<)<commit_msg>Fix the specs to work in a parallel test env<commit_after>require "stringio"

RSpec.describe Vmdb::Loggers do
  let(:log_file_name) { "#{SecureRandom.alphanumeric}.log" }
  let(:log_file_path) { Rails.root.join("log", log_file_name) }

  after do
    log_file_path.delete if log_file_path.exist?
  end

  def in_container_env(example)
    old_env = ENV.delete('CONTAINER')
    ENV['CONTAINER'] = 'true'

    example.run
  ensure
    ENV['CONTAINER'] = old_env
  end

  describe ".create_logger" do
    shared_examples "has basic logging functionality" do
      let(:log_file) { log_file_name }

      subject { described_class.create_logger(log_file) }

      let(:container_log) { subject.instance_variable_get(:@broadcast_logger) }

      before do
        # Hide the container logger output to STDOUT
        allow(container_log.logdev).to receive(:write) if container_log
      end

      it "responds to #<<" do
        expect(subject).to respond_to(:<<)
{'fraction_non_alphanumeric': 0.10741138560687433, 'fraction_numerical': 0.0, 'mean_word_length': 3.555012224938875, 'pattern_counts': {'":': 0, '<': 11, '<?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': '6861759', 'n_tokens_mistral': 642, 'n_tokens_neox': 606, 'n_words': 132}