【发布时间】:2013-01-30 12:47:20
【问题描述】:
app/models/zombie.rb
class Zombie < ActiveRecord::Base
attr_accessible :name
validates :name, presence: true
end
spec/models/zombie_spec.rb
require 'spec_helper'
describe Zombie do
it "is invalid without a name" do
zombie = Zombie.new
zombie.should_not be_valid
end
end
错误
僵尸 没有名字就无效 (FAILED - 1) 失败:
1) Zombie is invalid without a name Failure/Error: zombie.should_not be_valid ActiveRecord::StatementInvalid: Could not find table 'zombies' # ./spec/models/zombie_spec.rb:5:in `new' # ./spec/models/zombie_spec.rb:5:in `block (2 levels) in <top (required)>'在 0.02912 秒内完成 7 个示例,1 个失败
失败的例子:
rspec ./spec/models/zombie_spec.rb:4 # 没有名字的僵尸无效
用种子 12906 随机化
【问题讨论】:
-
你得到什么错误信息?
-
另外,如果 :name 是僵尸数据库表中的列,则不需要初始化方法定义的 attr_accessor 行。等效功能将作为 ActiveRecord 的一部分提供。
-
您是否运行迁移来创建僵尸表?
标签: ruby-on-rails rspec