How to speed up tests and use Factory Girl?

I really enjoy using Factory Girl to customize my tests. I can build association chains in one line. For instance:

Factory.create(:manuscript)

Automatically creates a magazine, magazine owner, manuscript author, etc. This allows me to keep my tuners really simple and fantastic.

However, of course, there is a cost. Creating multiple objects in the background means that my unit tests sometimes reach 0.8 seconds. This is great when your application is small, but now I have several hundred tests, and my specifications take a minute to work (not including the time it takes for the application to freeze). It starts to feel pain.

I'm not particularly interested in being as sharp as a mockery. At least while my application is relatively small, I would like to keep the abstractions of the Factory girls. I just want to figure out how to make them work a little faster.

Any suggestions?

+3
source share
2 answers

Not sure if there is a good solution to this problem. As Burlington suggested, you can save some time by using Factory.build, rather than Factory.create. But even this is not as fast as testing simple old ruby ​​objects. The fact is that a factory girl is not a good choice if you are very concerned about speed.

, , rspec-set . - - . before(:all), , reset .

+1

, Factory.build(:model). , . , . , SQlite.

+3

All Articles