如何处理测试中昂贵的fixture/factory_girl对象创建?

发布于 2024-12-19 13:38:32 字数 338 浏览 1 评论 0原文

对于我们系统中的所有用户,我们生成私钥/公钥对,这通常需要一两秒的时间。这在现场站点上并不是一个大问题,但它使得运行测试变得非常慢,并且缓慢的测试将无法运行。

我们的设置是带有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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

上课铃就是安魂曲 2024-12-26 13:38:32

您始终可以为您的测试制作一个假密钥对。预生成它们是行不通的,至少如果将它们存储在数据库中则不行,因为每次测试都应该清除数据库。我想你可以将它们存储在 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...

蝶舞 2024-12-26 13:38:32

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文