Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 43 lines (36 sloc) 1.349 kb
7a4202f Moved everthing to trunk
tsaleh authored
1 #!/usr/bin/env ruby
2 require 'fileutils'
abc3aa7 @showaltb convert_to_shoulda_syntax: use Dir::tmpdir instead of hardcoded /tmp
showaltb authored
3 require 'tmpdir'
4
5 TMP = Dir::tmpdir
7a4202f Moved everthing to trunk
tsaleh authored
6
7 def usage(msg = nil)
8 puts "Error: #{msg}" if msg
9 puts if msg
10 puts "Usage: #{File.basename(__FILE__)} normal_test_file.rb"
11 puts
12 puts "Will convert an existing test file with names like "
13 puts
14 puts " def test_should_do_stuff"
15 puts " ..."
16 puts " end"
17 puts
18 puts "to one using the new syntax: "
19 puts
20 puts " should \"be super cool\" do"
21 puts " ..."
22 puts " end"
23 puts
abc3aa7 @showaltb convert_to_shoulda_syntax: use Dir::tmpdir instead of hardcoded /tmp
showaltb authored
24 puts "A copy of the old file will be left under #{TMP} in case\nthis script just seriously screws up"
7a4202f Moved everthing to trunk
tsaleh authored
25 puts
26 exit (msg ? 2 : 0)
27 end
28
29 usage("Wrong number of arguments.") unless ARGV.size == 1
abc3aa7 @showaltb convert_to_shoulda_syntax: use Dir::tmpdir instead of hardcoded /tmp
showaltb authored
30 usage("Temp directory '#{TMP}' is not valid. Set TMPDIR environment variable to a writeable directory.") unless File.directory?(TMP) && File.writable?(TMP)
7a4202f Moved everthing to trunk
tsaleh authored
31
32 file = ARGV.shift
abc3aa7 @showaltb convert_to_shoulda_syntax: use Dir::tmpdir instead of hardcoded /tmp
showaltb authored
33 tmpfile = File.join(TMP, File.basename(file))
7a4202f Moved everthing to trunk
tsaleh authored
34 usage("File '#{file}' doesn't exist") unless File.exists?(file)
35
36 FileUtils.cp(file, tmpfile)
37 contents = File.read(tmpfile)
630ce17 @showaltb convert_to_should_syntax: fix clobbering of test names; leave existing s...
showaltb authored
38 contents.gsub!(/def test_should_(\S+)/) {|line| "should \"#{$1.tr('_', ' ')}\" do"}
39 contents.gsub!(/def test_(\S+)/) {|line| "should \"RENAME ME: test #{$1.tr('_', ' ')}\" do"}
7a4202f Moved everthing to trunk
tsaleh authored
40 File.open(file, 'w') { |f| f.write(contents) }
41
42 puts "File '#{file}' has been converted to 'should' syntax. Old version has been stored in '#{tmpfile}'"
Something went wrong with that request. Please try again.