开发者

In Rails, how to speed up machinist tests?

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) 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜