Pepino se transforma en archivos

I have two transforms in features/support/transforms/date_transform.rb

CAPTURE_YEAR = Transform /^(20\d{2})$/ do |year|
  year.to_i
end

CAPTURE_QUARTER = Transform /^(first|second|third|fourth)$/ do |quarter|
    {first: 1, second: 2, third: 3, fourth: 4}[quarter.to_sym]
end

I have another transform in features/support/transforms/number_transform.rb

CAPTURE_NUMBER = Transform /^\d+$/ do |number|
  number.to_i
end

I realize that the year and the number ones are nearly identical, but I don't want to simply rid the CAPTURE_YEAR variable. I'd like to do:

CAPTURE_YEAR = CAPTURE_NUMBER

Pero desafortunadamente, CAPTURE_NUMBER doesn't exist in the file I'm working with. Any idea how to include other transforms correctly in cucumber? I should have to explicitly require the file from each transform file right?

Gracias de antemano!

preguntado el 08 de noviembre de 11 a las 19:11

1 Respuestas

Cucumber just loads up whatever files are in the support directory. It seems to load them in alphabetical order (but I don't know that this is a documented/reliable behaviour - i.e. I wouldn't like to just rename the files to get around it).

Si estas tratando de declarar CAPTURE_YEAR before the file containing CAPTURE_NUMBER has been loaded, then it will fail, as you've discovered.

I think your best option is to explicitly require the number_transform file before trying to use constants declared inside it. Personally I don't have a problem declaring, within a file, which files it's dependent on.

You could also require it inside env.rb, as this gets parsed before any of the other support files, and might be a better option if many of your other files depend on it as well.

respondido 10 nov., 11:18

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.