FactoryGirl::DefinitionProxy
defines method_missing
to call add_attribute
using the missing method's name, so you should be able to sub that in instead:
FactoryGirl.define do
factory :my_model do
field1 'some text'
add_attribute(:"data-field2", 'some_element_classname')
add_attribute(:"data-field3") { # add_attribute with block }
end
end