Sha256: 991ed092907a923fe596359945d8e655f70784e0dd4b3c9561119c56fe6c112a
Contents?: true
Size: 1.38 KB
Versions: 4
Compression:
Stored size: 1.38 KB
Contents
# typed: strict # frozen_string_literal: true require "fileutils" module Tapioca module Helpers module Test module Content extend T::Sig extend T::Helpers requires_ancestor { Kernel } sig { void } def teardown super remove_tmp_path end sig { params(args: String).returns(String) } def tmp_path(*args) @tmp_path = T.let(@tmp_path, T.nilable(String)) @tmp_path ||= Dir.mktmpdir T.unsafe(File).join(@tmp_path, *args) end sig { void } def remove_tmp_path FileUtils.rm_rf(tmp_path) end sig { params(name: String, content: String, require_file: T::Boolean).returns(String) } def add_ruby_file(name, content, require_file: true) add_content_file(name, content).tap do |file_name| Tapioca.silence_warnings { require(file_name) } if require_file end end sig { params(name: String, content: String).returns(String) } def add_content_file(name, content) file_name = tmp_path("lib/#{name}") raise ArgumentError, "a file named '#{name}' was already added; cannot overwrite." if File.exist?(file_name) FileUtils.mkdir_p(File.dirname(file_name)) File.write(file_name, content) file_name end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems