[rspec-users] Validations are making me want to scream. help please

David Chelimsky dchelimsky at gmail.com
Sat Jul 11 11:50:27 EDT 2009

On Sat, Jul 11, 2009 at 10:42 AM, Michael<magic6435 at gmail.com> wrote:
> Simply testing that my validations are working for a model called
> Project.
> class Project < ActiveRecord::Base
>  validates_presence_of :brief
> end
> require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
> describe Project do
>  before(:each) do
>    @project = Project.new(:title => "project title", :brief =>
> "project brief")
>  end
>  it "should create a new instance given valid attributes" do
>    @project.should be_valid
>  end
> end
> ActiveRecord::RecordInvalid in 'Project should create a new instance
> given valid attributes'
> Validation failed: Brief can't be blank
> How on earth can that be failing? its driving me nuts, i have a few
> other tests that check the exact same way(method taken from the Rspec
> book) so why all the sudden would it stop working on a new model. Blah
> thanks for any help.

The fact that it's raising an error suggests that something is trying
to save the Project. Otherwise you'd just get back something like
"expected valid? to be true". Since rspec-rails doesn't try to save
the record, my guess is that there is some other code introducing
itself. Either in the application code, a plugin, or perhaps an rspec
extension library that has its own be_valid matcher. Any of that

> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list