1
0
Fork 0
mirror of https://github.com/thoughtbot/shoulda-matchers.git synced 2022-11-09 12:01:38 -05:00

convert_to_shoulda_syntax: use Dir::tmpdir instead of hardcoded /tmp

This commit is contained in:
Bob Showalter 2008-07-29 15:59:43 -04:00 committed by Ryan McGeary
parent 630ce17443
commit abc3aa73a4

View file

@ -1,5 +1,8 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
require 'fileutils' require 'fileutils'
require 'tmpdir'
TMP = Dir::tmpdir
def usage(msg = nil) def usage(msg = nil)
puts "Error: #{msg}" if msg puts "Error: #{msg}" if msg
@ -18,16 +21,16 @@ def usage(msg = nil)
puts " ..." puts " ..."
puts " end" puts " end"
puts puts
puts "A copy of the old file will be left under /tmp/ in case this script just seriously screws up" puts "A copy of the old file will be left under #{TMP} in case\nthis script just seriously screws up"
puts puts
exit (msg ? 2 : 0) exit (msg ? 2 : 0)
end end
usage("Wrong number of arguments.") unless ARGV.size == 1 usage("Wrong number of arguments.") unless ARGV.size == 1
usage("This system doesn't have a /tmp directory. wtf?") unless File.directory?('/tmp') usage("Temp directory '#{TMP}' is not valid. Set TMPDIR environment variable to a writeable directory.") unless File.directory?(TMP) && File.writable?(TMP)
file = ARGV.shift file = ARGV.shift
tmpfile = "/tmp/#{File.basename(file)}" tmpfile = File.join(TMP, File.basename(file))
usage("File '#{file}' doesn't exist") unless File.exists?(file) usage("File '#{file}' doesn't exist") unless File.exists?(file)
FileUtils.cp(file, tmpfile) FileUtils.cp(file, tmpfile)