Created
February 23, 2011 22:41
-
-
Save jscruggs/841352 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
REGXS = { | |
/context/ => "describe", | |
/assert_equal\(?\s*([^,]+), (.*)\s*\)?$/ => "\\2.should == \\1", | |
/setup do/ => "before( :each ) do", | |
/should([^_])/ => "it\\1", | |
/require File.dirname.*$/ => "require \"spec_helper\"", | |
/class (.*)Test < [^:]*::TestCase/ => "describe \\1 do" | |
} | |
infile = ARGV.first | |
outfile = infile.gsub( /_test.rb/, "_spec.rb" ).gsub( %r{test/unit/helpers}, "spec/helpers" ) | |
File.open( outfile, "w" ) do |f| | |
ARGF.each do |line| | |
out = REGXS.inject( line ) do |result, subs| | |
regx, substitution = subs | |
result = result.gsub( regx, substitution ) | |
end | |
f.puts out | |
end | |
end | |
system "mate #{outfile}" | |
system "git rm #{infile} && git add #{outfile}" | |
system "bundle exec spec #{outfile}" | |
puts "\n\nSUCCESS! Now do this:" | |
puts "rake && git commit -m \"Converted #{File.basename infile} from should to rspec in #{File.basename outfile}\"" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment