[rspec-users] Is #valid? automatically called?

Nick Hoffman nick at deadorange.com
Thu Feb 12 14:03:49 EST 2009

Does RSpec automatically call #valid? on ActiveRecord models?

For instance, when this example is run:

it 'should reject a nil value' do
   @form = TimeShiftForm.new :file => nil

   puts "@form.errors.count = <<#{@form.errors.count}>>"
   @form.should have(1).error_on :file
   puts "@form.errors.count = <<#{@form.errors.count}>>"

This is printed:
@form.errors.count = <<0>>
@form.errors.count = <<1>>

However, I never called @form.valid? , which leads me to believe that  
RSpec called it for me.

If RSpec does in fact call #valid? automatically, should we refrain  
from manually calling #valid? ?

More information about the rspec-users mailing list