应用程序/模型/zombie.rb
class Zombie < ActiveRecord::Base
attr_accessible :name
validates :name, presence: true
end
规格/模型/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
错误
没有名字的僵尸是无效的(失败 - 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