Rspec检查ActiveModel ::错误

时间:2012-06-14 00:21:59

标签: ruby-on-rails ruby-on-rails-3 rspec

有没有更好的方法来编写此规范?这可以 但是 我不喜欢我必须调用f.valid?来填充f.errors。

it "fails to save the record because the name is blank" do
  f = Foo.new
  f.valid?
  f.errors.include?(:name).should be_true
end

1 个答案:

答案 0 :(得分:4)

it "fails to save the record because the name is blank" do
  Foo.create.errors.should include :name
end