views:

114

answers:

1

I'm replacing test fixtures with Machinist. But using Machinist to set up test data is very slow, because whenever a test method is run some new data are made by Machinist and saved to database. Is there any way to cache the data in memory so that using Machinist isn't so slow?

Thanks, Bryan

+1  A: 

1) Try SomeModel.make_unsaved if you don't actually need it to be saved.

2) Look for ways to create lighter versions of the objects. Maybe you can avoid creating the associated objects. For example: BlogComment.make(:gravatar => nil) # avoid creating the gravatar image Or if you usually need the lighter version, you could flip that around and have the regular BlogComment.make create the light object (no gravatar) whereas BlogComment.make(:with_gravatar) would do the extra work.

3) Avoid offsite hits to web services (Google maps, S3, etc.) if you're not specifically doing an integration test for that service. Use stubbing to prevent those methods on the object you're testing from actually connecting to the external service.

Jamie Flournoy
Thanks. I've finally come down to transactional tests. http://github.com/myronmarston/factory_data_preloader
Bryan
1) is a nice. But I want to make sure the objects work well with database.2) this works well with unit tests. For functional tests, we usually need to set up all the associated objects
Bryan