I’m just wondering whether it’s possible to create an attribute called “alias” using FactoryGirl, since alias is a reserved word in Ruby.
FactoryGirl.define do
factory :blah do
name "dummy"
alias "dummy"
end
end
I’ve tried various combinations of escaping things but can’t get anything useful to work.
Ruby doesn’t know whether you’re trying to call a method called
aliasor alias one method as another, and defaults to the latter. You can disambiguate by doingie, by explicitly specifying the receiver. This is usually the way to go in other cases where it is ambiguous whether you are calling a method or doing something else e.g.
to call the
foo=method rather than create a local variable called foo.For a small number of field names this won’t work. Factory girl’s DSL uses
method_missingso if the DSL object has a method of that name it will be called instead. In those cases you can do what the DSL sugar normal does for you and calladd_attributedirectly:is the same as