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
But unfortunately, 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?
Thanks in advance!
Cucumber just loads up whatever files are in the
supportdirectory. 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).If you’re trying to declare
CAPTURE_YEARbefore the file containingCAPTURE_NUMBERhas been loaded, then it will fail, as you’ve discovered.I think your best option is to explicitly require the
number_transformfile 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.