I am working on Ruby on Rails rspec testing and I have a question. Apparently, I have to create a dictionary, sort like
@example = {:attr1 => "somevalue", :attr2 => "some",
:attr3 => "someother", :stt => "abc"}
It is a very long dictionary so I would like to make it inside a factory. That would make the test look nicer.
I have been looking around but I only see FactoryGirl is designed for ActiveRecord object. Does anyone know how to use FactoryGirl to make a dictionary like this ?
Thanks for your helps.
You can, in fact, use FactoryGirl for this:
See Custom Construction. Basically, you provide
initialize_withto the factory definition and use your initializer function to set the dictionary values to what you need. You still get the full power of sequences, traits, etc, but can get back any Ruby object… not just an ActiveRecord.