Michael
2009-Jul-11 15:42 UTC
[rspec-users] Validations are making me want to scream. help please
Simply testing that my validations are working for a model called Project. MODEL class Project < ActiveRecord::Base validates_presence_of :brief end SPEC 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 ERROR ActiveRecord::RecordInvalid in ''Project should create a new instance given valid attributes'' Validation failed: Brief can''t be blank POST 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.
David Chelimsky
2009-Jul-11 15:50 UTC
[rspec-users] Validations are making me want to scream. help please
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. > > MODEL > class Project < ActiveRecord::Base > ?validates_presence_of :brief > end > > SPEC > 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 > > ERROR > ActiveRecord::RecordInvalid in ''Project should create a new instance > given valid attributes'' > Validation failed: Brief can''t be blank > > > POST > 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 feasible?> _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Yi Wen
2009-Jul-11 17:00 UTC
[rspec-users] Validations are making me want to scream. help please
There is a validation error, which means you were trying to save the object somewhere. Check both your tests and code, to find out where. On Jul 11, 2009, at 10:42 AM, Michael wrote:> Simply testing that my validations are working for a model called > Project. > > MODEL > class Project < ActiveRecord::Base > validates_presence_of :brief > end > > SPEC > 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 > > ERROR > ActiveRecord::RecordInvalid in ''Project should create a new instance > given valid attributes'' > Validation failed: Brief can''t be blank > > > POST > 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. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users