如何处理测试中昂贵的fixture/factory_girl对象创建?
对于我们系统中的所有用户,我们生成私钥/公钥对,这通常需要一两秒的时间。这在现场站点上并不是一个大问题,但它使得运行测试变得非常慢,并且缓慢的测试将无法运行。
我们的设置是带有factory_girl 和rspec 的Rails 3.1。
我尝试使用返回随机的方法提前创建(10 个左右),但这似乎是有问题的:也许它们已从数据库中清除并且无法用于后续测试......我没有把握。
这可能有用: https://github.com/pcreux/rspec-set - 任何其他想法?
For all users in our system, we generate a private/public key pair, which often takes a second or two. That's not a deal breaker on the live site, but it makes running the tests extremely slow, and slow tests won't get run.
Our setup is Rails 3.1 with factory_girl and rspec.
I tried creating (10 or so) some ahead of time with a method to return a random one, but this seems to be problematic: perhaps they're getting cleared out of the database and are unavailable for subsequent tests... I'm not sure.
This might be useful: https://github.com/pcreux/rspec-set - any other ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您始终可以为您的测试制作一个假密钥对。预生成它们是行不通的,至少如果将它们存储在数据库中则不行,因为每次测试都应该清除数据库。我想你可以将它们存储在 YAML 文件或其他文件中,然后从那里读取它们......
You can always make a fake key pair for your tests. Pregenerating them won't work, at least not if you store them in the DB, because the DB should get cleared for every test. I suppose you could store them in a YAML file or something and read them from there...
https://github.com/pcreux/rspec-set 足以满足我们的需要,与 after/all 块相结合,以清理数据库中留下的粪便。
https://github.com/pcreux/rspec-set was good enough for what we need, combined with an after/all block to clean up after the droppings it leaves in the database.