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

Answers


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

Need Your Help

How to post a file via HTTP with cookies using python poster lib

python http cookies file-upload

Using Chris Atlee's python poster library is there any way to include cookie handling?

Android studio: can we directly edit string.xml from java source file?

android android-studio

While editing code sometimes we might need to change the string value in strings.xml, what is the fastest way to do that?