Trouble on evaluating other model data

纵饮孤独 提交于 2019-12-25 04:06:20

问题


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
  +[]

Is it possible to solve the above error\problem? If so, how can I do?


回答1:


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)

or

using something a factory girl to create some test data for yourself in the before block of your spec.



来源:https://stackoverflow.com/questions/7457403/trouble-on-evaluating-other-model-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!