Rails 4 - 所有测试都失败(甚至断言为真) [英] Rails 4 - All Tests Failing (even Assert true)
问题描述
Rails 新手,刚刚开始学习测试.我们遇到了一个问题,这个问题可能有一个简单的答案,却让我们难住了.
New to rails and just getting started learning testing. We're having a problem that probably has a simple answer that has us stumped.
我们已经编写了一些代码并使其在开发中工作(只是静态代码和带有设计的登录系统).我们文件中唯一的测试用例是由 rails 生成的,例如:
We have wrote some code and got it working in development (just static code and a login system w/ Devise). The only test cases in our file were generated by rails, for example:
test "should get about" do
get :about
assert_response :success
end
然而,当我们运行 bundle exec rake test
时,令我们惊讶的是,我们每次测试都失败了.
However, when we run bundle exec rake test
, to our surprise, we fail every single test.
10 runs, 0 assertions, 0 failures, 10 errors, 0 skips
每次测试都有相同的错误:
Each test has the same error:
ActiveRecord::StatementInvalid: PG::NotNullViolation: ERROR: null value in column "email" violates not-null constraint
DETAIL: Failing row contains (980190962, null, 2015-10-27 09:40:30, 2015-10-27 09:40:30).
: INSERT INTO "leads" ("created_at", "updated_at", "id") VALUES ('2015-10-27 09:40:30', '2015-10-27 09:40:30', 980190962)
通过阅读该错误,我们的 leads
表中似乎有一些没有电子邮件的记录.电子邮件是迁移后后来创建的一个字段.但是,通过 psqlAdmin 查看,每一行都有一个电子邮件.此外,如果我们在 chrome 中加载页面后查看控制台,则没有错误.
By reading that error, it seems like there is some record in our leads
table without an email. E-mail was a field created later after a migration. However, looking through psqlAdmin, every row has an e-mail. Furthermore, if we look in the console after loading the pages in chrome, there are no errors.
即使是最基本的测试也会因相同的错误而失败:
Even the most basic test is failing with the same error:
test "the truth" do
assert true
end
我唯一的猜测是有一些默认种子正在发生,它试图在没有电子邮件的情况下将一个字段插入到潜在客户中.但是,seeds.rb
是完全空白的.
My only guess is that there is some default seeding going on, and it is trying to insert a field into leads without an e-mail. However, seeds.rb
is completely blank.
这是我在终端中通话的开始:
Here is the start of my call in terminal:
Macintosh-2:triplanding Calvino$ bundle exec rake test
Run options: --seed 15348
# Running:
EEEEEEEEEE
Finished in 0.108843s, 91.8753 runs/s, 0.0000 assertions/s.
- 为什么这些测试失败了?
- 为什么
leads
甚至会参与像 assert true 这样的测试.
- Why are these tests failing?
- Why is the
leads
even involved in a test like assert true.
先谢谢你!
更新
这是我的 fixture/leads.yml 文件.我们没有编辑它,这是生成的:
Here is my fixture/leads.yml file. We did not edit it, this is what was generated:
one: {}
# column: value
#
two: {}
# column: value
推荐答案
很可能是因为您的设备无法运行,原因是:
Moste likely it is because your fixtures cannot run due to:
ActiveRecord::StatementInvalid: PG::NotNullViolation: ERROR: null value in column "email" violates not-null constraint
检查您的潜在客户固定装置是否包含空电子邮件,它应该可以工作!
Check that none of your fixtures for leads contains a null email and it should probably work!
每当您在 rails 上运行测试时,它都会设置测试数据库(这就是即使 assert true
失败的原因)
Whenever you run tests on rails it will setup the test-database (this is the reason even assert true
fails)
这篇关于Rails 4 - 所有测试都失败(甚至断言为真)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!