Kyle Decot
Kyle Decot

Reputation: 20815

Rspec checking ActiveModel::Errors

Is there a better way to write this spec? This works but I don't like the fact that I have to call f.valid? to get f.errors to populate.

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

Upvotes: 2

Views: 841

Answers (1)

Mori
Mori

Reputation: 27779

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

Upvotes: 4

Related Questions