导轨奇怪的单元测试失败

编程入门 行业动态 更新时间:2024-10-11 09:24:15
本文介绍了导轨奇怪的单元测试失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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?

编辑:users表来自设计宝石,如果这有帮助

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

推荐答案

从 guides.rubyonrails/ test.html

默认情况下,Rails将自动从您的设备的测试/夹具文件夹中加载所有夹具,功能测试。加载涉及三个步骤:

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.

更多推荐

导轨奇怪的单元测试失败

本文发布于:2023-10-10 21:55:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479864.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:导轨   单元测试   奇怪

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!