Sha256: 36b79bfbceabff57a2837488354b867d1add6495cf23c20540304986e4906970

Contents?: true

Size: 1002 Bytes

Versions: 10

Compression:

Stored size: 1002 Bytes

Contents

# frozen_string_literal: true

require "securerandom"
require "fileutils"
require "erb"
require "ostruct"

UNIQUE_FILES_DIR = "./test/unique_files"

def require_unique_file(file = "dog.rb", variables = {})
  uuid = SecureRandom.uuid
  dir = "#{UNIQUE_FILES_DIR}/#{uuid}"
  file_name = file.sub(".erb", "")
  temp_file = "#{dir}/#{file_name}"
  FileUtils.mkdir_p(Pathname.new(temp_file).dirname.to_s)
  file_contents = File.read("./test/#{file}")
  file_contents = ERB.new(file_contents).result(OpenStruct.new(variables).instance_eval { binding }) if variables.any?
  File.write(temp_file, file_contents)
  require temp_file
  Coverband::Utils::RelativeFileConverter.convert(File.expand_path(temp_file))
end

def require_class_unique_file
  @dogs ||= 0
  @dogs += 1
  require_unique_file("dog.rb.erb", dog_number: @dogs)
end

def remove_unique_files
  FileUtils.rm_r(UNIQUE_FILES_DIR) if File.exist?(UNIQUE_FILES_DIR)
end

if defined?(Minitest)
  Minitest.after_run do
    remove_unique_files
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
coverband-6.1.4 test/unique_files.rb
coverband-6.1.3 test/unique_files.rb
coverband-6.1.2 test/unique_files.rb
coverband-6.1.2.rc.1 test/unique_files.rb
coverband-6.1.1 test/unique_files.rb
coverband-6.1.0 test/unique_files.rb
coverband-6.0.3.rc.4 test/unique_files.rb
coverband-6.0.3.rc.3 test/unique_files.rb
coverband-6.0.3.rc.2 test/unique_files.rb
coverband-6.0.3.rc.1 test/unique_files.rb