评估其他模型数据时遇到问题 [英] Trouble on evaluating other model data
本文介绍了评估其他模型数据时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是 Ruby on Rails 3.0.9 和 RSpec 2.在我的规范文件中,我有如下代码:
I am using Ruby on Rails 3.0.9 and RSpec 2. In my spec file I have code like the following:
describe User do
let(:authorizations) { Authorization.all.map(&:name) }
it "should have a 'registered' value" do
authorizations.should include("registered")
end
end
当我运行上述测试时,我得到:
When I run the above test I get:
User should have a 'registered' value
Failure/Error: authorizations.should include("registered")
expected [] to include "registered"
Diff:
@@ -1,2 +1,2 @@
-registered
+[]
是否可以解决上述错误\问题?如果是这样,我该怎么办?
推荐答案
上面告诉我,你的测试数据库中有所有空表.您应该考虑播种 你的开发/测试数据库.(如果您认为授权是一种查找实体)
The above tells me that you have you all empty tables in your test database. You should either consider seeding your dev/test databases. (in case your consider Authorization to be a look up kind of entity)
或
使用工厂女孩在规范的 before 块中为自己创建一些测试数据.
using something a factory girl to create some test data for yourself in the before block of your spec.
这篇关于评估其他模型数据时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文