Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
executable file 43 lines (36 sloc) 1.32 KB
#!/usr/bin/env ruby
require 'fileutils'
require 'tmpdir'
TMP = Dir::tmpdir
def usage(msg = nil)
puts "Error: #{msg}" if msg
puts if msg
puts "Usage: #{File.basename(__FILE__)} normal_test_file.rb"
puts "Will convert an existing test file with names like "
puts " def test_should_do_stuff"
puts " ..."
puts " end"
puts "to one using the new syntax: "
puts " should \"be super cool\" do"
puts " ..."
puts " end"
puts "A copy of the old file will be left under #{TMP} in case\nthis script just seriously screws up"
exit (msg ? 2 : 0)
usage("Wrong number of arguments.") unless ARGV.size == 1
usage("Temp directory '#{TMP}' is not valid. Set TMPDIR environment variable to a writeable directory.") unless && File.writable?(TMP)
file = ARGV.shift
tmpfile = File.join(TMP, File.basename(file))
usage("File '#{file}' doesn't exist") unless File.exists?(file)
FileUtils.cp(file, tmpfile)
contents =
contents.gsub!(/def test_should_(\S+)/) {|line| "should \"#{$'_', ' ')}\" do"}
contents.gsub!(/def test_(\S+)/) {|line| "should \"RENAME ME: test #{$'_', ' ')}\" do"}, 'w') { |f| f.write(contents) }
puts "File '#{file}' has been converted to 'should' syntax. Old version has been stored in '#{tmpfile}'"
Jump to Line
Something went wrong with that request. Please try again.