Rails中有多个夹具集? [英] Multiple Fixture Sets in Rails?

查看:68
本文介绍了Rails中有多个夹具集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以为Rails测试使用不同的夹具组(您可以将其称为夹具配置文件")?

Is there a way to have different fixture sets (what you might call a "fixture profile") for Rails tests?

我发现最好的是 2006年推出的Rails 1.3插件.我以为对这种东西会有更多的需求.就我而言,我想要一个离线"配置文件,其中包括所有数据的缓存,以及另一个在线"配置文件,它需要获取数据.

The best I've found is a Rails 1.3 plugin from 2006. I thought there'd be more demand for this kind of thing. In my case, I want an "offline" profile which would include a cache of all data, and another "online" profile which would be required to fetch data.

推荐答案

由于没有人回答,我会说最好的解决方案似乎是

Since no-one's answered, I'll say that the best solution here seems to be Factory Girl. It's not built-in Rails fixtures, but it's really an enhanced version of fixtures, and one which supports the use case in this question. The problem with fixtures is they closely tie the fixture file to the class. But with factory girl, you can have as many factory definitions as you like.

这篇关于Rails中有多个夹具集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆