Sha256: 848e641c39b8ad46193faafcef3b0b70dbd7c2d4472e66af5ee14c4767313ab8

Contents?: true

Size: 1.22 KB

Versions: 34

Compression:

Stored size: 1.22 KB

Contents

#!/usr/bin/env ruby
require 'fileutils'

def usage(msg = nil)
  puts "Error: #{msg}" if msg
  puts if msg
  puts "Usage: #{File.basename(__FILE__)} normal_test_file.rb"
  puts
  puts "Will convert an existing test file with names like "
  puts
  puts "  def test_should_do_stuff"
  puts "    ..."
  puts "  end"
  puts
  puts "to one using the new syntax: "
  puts
  puts "  should \"be super cool\" do"
  puts "    ..."
  puts "  end"
  puts
  puts "A copy of the old file will be left under /tmp/ in case this script just seriously screws up"
  puts
  exit (msg ? 2 : 0)
end

usage("Wrong number of arguments.") unless ARGV.size == 1
usage("This system doesn't have a /tmp directory.  wtf?") unless File.directory?('/tmp')

file = ARGV.shift
tmpfile = "/tmp/#{File.basename(file)}"
usage("File '#{file}' doesn't exist") unless File.exists?(file)

FileUtils.cp(file, tmpfile)
contents = File.read(tmpfile)
contents.gsub!(/def test_should_(.*)\s*$/, 'should "\1" do')
contents.gsub!(/def test_(.*)\s*$/, 'should "RENAME ME: test \1" do')
contents.gsub!(/should ".*" do$/) {|line| line.tr!('_', ' ')}
File.open(file, 'w') { |f| f.write(contents) }

puts "File '#{file}' has been converted to 'should' syntax.  Old version has been stored in '#{tmpfile}'"

Version data entries

34 entries across 34 versions & 10 rubygems

Version Path
akitaonrails-resource_controller-0.5.2 test/vendor/plugins/shoulda/bin/convert_to_should_syntax
akitaonrails-resource_controller-0.5.3 test/vendor/plugins/shoulda/bin/convert_to_should_syntax
giraffesoft-resource_controller-0.4.10 test/vendor/plugins/shoulda/bin/convert_to_should_syntax
giraffesoft-resource_controller-0.4.12 test/vendor/plugins/shoulda/bin/convert_to_should_syntax
giraffesoft-resource_controller-0.4.9 test/vendor/plugins/shoulda/bin/convert_to_should_syntax
giraffesoft-resource_controller-0.5.2 test/vendor/plugins/shoulda/bin/convert_to_should_syntax
giraffesoft-resource_controller-0.5.3 test/vendor/plugins/shoulda/bin/convert_to_should_syntax
jcnetdev-shoulda-4.2 bin/convert_to_should_syntax
korin-resource_controller-0.5.3 test/vendor/plugins/shoulda/bin/convert_to_should_syntax
nileshtrivedi-lp_resource_builder-0.5.1 test/vendor/plugins/shoulda/bin/convert_to_should_syntax
nileshtrivedi-lp_resource_builder-0.5.3 test/vendor/plugins/shoulda/bin/convert_to_should_syntax
nileshtrivedi-safe_resource-0.5.3 test/vendor/plugins/shoulda/bin/convert_to_should_syntax
pager-resource_controller-1.0.20080513 test/vendor/plugins/shoulda/bin/convert_to_should_syntax
rotuka-shoulda-gem-0.0.1 bin/convert_file_to_shoulda
spree-0.11.4 vendor/plugins/resource_controller/test/vendor/plugins/shoulda/bin/convert_to_should_syntax
spree-0.11.3 vendor/plugins/resource_controller/test/vendor/plugins/shoulda/bin/convert_to_should_syntax
spree-0.8.4 vendor/plugins/resource_controller/test/vendor/plugins/shoulda/bin/convert_to_should_syntax
spree-0.8.5 vendor/plugins/resource_controller/test/vendor/plugins/shoulda/bin/convert_to_should_syntax
resource_controller-0.4.9 test/vendor/plugins/shoulda/bin/convert_to_should_syntax
resource_controller-0.5.3 test/vendor/plugins/shoulda/bin/convert_to_should_syntax