Solution John Hinnegan offers sound, but it is better to use the method FactoryGirl.createto initialize the object, since it usually gives you a valid object. For example, after(:create)it will not be called if you use MyObject.new.
@attributes = FactoryGirl.attributes_for(:my_object)
my_object = FactoryGirl.create(:my_object, @attributes)
expect(my_object.some_property).to eq @attributes[:some_property]
source
share