[rspec-users] Validations aren't being performed when running 'rspec spec'

Craig Demyanovich cdemyanovich at gmail.com
Thu Feb 24 08:48:33 EST 2011

On Wed, Feb 23, 2011 at 10:29 AM, Tom Milewski <tmilewski at gmail.com> wrote:

> Model:
> validates_presence_of :name, :location, :email...
> Test:
> it "should ensure that name is present" do
>      Factory.build(:public_agent, :name => nil).should
> have(1).error_on(:name)
> end
> All of these tests do not return errors and do add the invalid records
> to the database.
> Has anyone else had this happen? Suggestions?

Though I'm still using RSpec 1, I do use FactoryGirl. Factory.build only
instantiates a new record; it does not save it. Thus, the example that you
shared should not create a record. Are you sure that the invalid records
that you're seeing in the database are from this example?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110224/837b3415/attachment.html>

More information about the rspec-users mailing list