Thinking on hiring me?

Please read

Fernando Guillén

a Freelance Web Developer

cabecera decorativa

software development as an artistic expression

Ruby on Rails: script para volver a la anterior sintaxis de tests

El nuevo generador de scaffold de RoR 2.2 no se lleva bien con Texmate, la nueva sintaxis para tests impide que usemos el utilísimo atajo de teclado ‘ctrl + shift + R‘ para ejecutar solamente uno de los tests de todo el fichero.

Este script convierte las líneas tipo:

test "should get new" do

en:

def test_should_get_new

Seguro que esto le espanta a más de uno, pero mientras Texmate no soporte la nueva sintaxis yo tampoco la soporto :). El script es la primera versión que me ha salido, se aceptan mejoras.

El script:

if ARGV[0].nil?
  puts "Indica la ruta al fichero" 
  exit
end
 
if not File.exists?(ARGV[0])
  puts "Fichero no encontrado: #{ARGV[0]}" 
  exit
end
 
result = ""
 
File.open(ARGV[0]).read.each do |line|
  if line =~ /^\s*test ".*" do$/
    line.gsub!( /\"\sdo\s*/, "" )
    line.gsub!( /"/, "" )
    line.gsub!( /^\s*/, "" )
    line.gsub!( /\s/, "_" )
    line.gsub!( /^/, "def ")
 
    line = "  " + line + "\n"
  end
 
  result << line
end
 
File.new( ARGV[0], "w+" ).puts( result )
Leave a comment

You must be logged in to post a comment.

a Freelance Web Developer is proudly powered by WordPress
Entries (RSS) and Comments (RSS).

Creative Commons License
Fernando Guillen's blog by Fernando Guillen is licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License.