rails 奇怪的单元测试失败 [英] rails strange unit test fails

查看:19
本文介绍了rails 奇怪的单元测试失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试运行这个最简单的单元测试:

I try to run this simplest unit test:

   test "the truth" do
     assert true
   end

像这样:

ruby -Itest test/unit/my_model_test.rb

(文件中只有一个测试,实际上整个站点中)

(there is the only one test in the file, and actually in the whole site)

失败并显示以下消息:

ActiveRecord::RecordNotUnique: SQLite3::ConstraintException: column email is not unique: INSERT INTO "users"... [some values to insert here]

现在我确实有一个名为users"的表,但除此之外,我从未要求对其进行任何测试,我什至没有进行此类测试.这个错误从何而来?我如何只运行我的测试?

now I do have a table named "users" but other than that I have never asked to do any tests on it nor do I even have such tests. Where does this error come from? How do I run just my test?

如果有帮助,用户"表来自设计宝石

the "users" table comes from the devise gem if that helps

推荐答案

引用自 http://guides.rubyonrails.org/testing.html

Rails 默认自动从用于单元和功能测试的 test/fixtures 文件夹.加载中包括三个步骤:

Rails by default automatically loads all fixtures from the test/fixtures folder for your unit and functional test. Loading involves three steps:

  • 从与夹具对应的表中删除任何现有数据
  • 将夹具数据加载到表格中
  • 将夹具数据转储到变量,以防您想直接访问它

所以我认为您需要检查这些装置.另外我建议你阅读那个教程.写的真好.

So I think you need to check those fixtures. Also I suggest you to read that tutorial. It is very well written.

这篇关于rails 奇怪的单元测试失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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