Rails单元测试不会加载夹具 [英] Rails unit testing doesn't load fixtures

查看:54
本文介绍了Rails单元测试不会加载夹具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

rake test:units在我当前的应用程序中失败,因为缺少所需的灯具数据.

rake test:units fails in my current application, because the needed data of the fixtures is missing.

如果我通过rake db:fixtures:load RAILS_ENV=test手动加载灯具,则单元测试正在运行,但是rake清除了测试数据库.

If I'm loading the fixtures manually via rake db:fixtures:load RAILS_ENV=test the unit tests are working, but rake purges the test database.

我的test_helper包含fixtures :all,并且我的测试正在继承它-但是固定装置根本没有加载.

My test_helper includes fixtures :all and my tests are inheriting from it - but the fixtures are simply not loading.

我现在一无所知,可能真的需要一些帮助!

I'm kind of clueless at the moment and could really need some help!

我已经尝试了很多,我认为这与本项目中使用的某些环境设置或插件有关.有人知道在哪里可以了解到为测试环境加载了哪些文件吗?

I've tried a lot and I think it has to do with some environment settings or plugins used in this project. Does anyone know where to read about which files are loaded for the testing environment?

推荐答案

我终于找到了问题所在,尽管解决方案有点过分.

I finally found the problem, although the solutions is kind of hacky.

一个插件依赖数据库中至少有一行数据.所以发生了什么事:

One plugin is relying that there is some data in the database, at least one row. So what happened was:

  1. rake加载数据库架构
  2. rake尝试加载环境
  3. 环境包括插件
  4. 由于至少缺少一行而导致插件加载失败
  5. 未加载任何灯具

骇人听闻的解决方案是:将所需数据直接加载到架构中,而不是放入固定装置中,因为它们已加载到很晚.

The hacky solution is: put the needed data directly into schema and not into a fixtures, because it's loaded to late.

我将寻找一种更方便的解决方案,如果找到答案,则会对其进行更新.

I'll search for a more convenient solution and will update this answer if I found one.

这篇关于Rails单元测试不会加载夹具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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