Sha256: 2b7d95298cabfe17b0dcd044c32ecb8a5ea4611033fc8b8b94d60f784f3a2311

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

# Creates a temporary directory in the current working directory
# for temporary files created while running the specs. All specs
# should clean up any temporary files created so that the temp
# directory is empty when the process exits.

SPEC_TEMP_DIR = "#{File.expand_path(Dir.pwd)}/rubyspec_temp"

SPEC_TEMP_UNIQUIFIER = "0"

SPEC_TMEM_DIR_PID = Process.pid

at_exit do
  begin
    if SPEC_TMEM_DIR_PID == Process.pid
      Dir.delete SPEC_TEMP_DIR if File.directory? SPEC_TEMP_DIR
    end
  rescue SystemCallError
    STDERR.puts <<-EOM

-----------------------------------------------------
The rubyspec temp directory is not empty. Ensure that
all specs are cleaning up temporary files:
  #{SPEC_TEMP_DIR}
-----------------------------------------------------

    EOM
  rescue Object => e
    STDERR.puts "failed to remove spec temp directory"
    STDERR.puts e.message
  end
end

class Object
  def tmp(name, uniquify=true)
    Dir.mkdir SPEC_TEMP_DIR unless File.exists? SPEC_TEMP_DIR

    if uniquify and !name.empty?
      slash = name.rindex "/"
      index = slash ? slash + 1 : 0
      name.insert index, "#{SPEC_TEMP_UNIQUIFIER.succ!}-"
    end

    File.join SPEC_TEMP_DIR, name
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mspec-1.5.20 lib/mspec/helpers/tmp.rb
mspec-1.5.19 lib/mspec/helpers/tmp.rb
mspec-1.5.18 lib/mspec/helpers/tmp.rb