Ashley Moran
2007-Mar-26 13:59 UTC
[rspec-users] Failure creating model in spec setup not reported?
Hi I''ve just tracked down a wierd error that AFAICT is caused by an error not being raised in the setup: context "An Asset" do setup do @provider = Provider.create(:name => "Provider1") @product = Product.new(:name => "Product1", :provider => @provider) @applicant = Applicant.new(:first_name => "Fred", :last_name => "Flinstone", :email => "fred at flinstone.com") @asset = Asset.new(:value => BigDecimal("250")) end specify "should have many quote parameters" do @asset.applicant = @applicant quote_parameters_1 = QuoteParameters.new(:term => 36, :applicant => @applicant, :product => @product) quote_parameters_2 = QuoteParameters.new(:term => 48, :applicant => @applicant, :product => @product) @asset.should respond_to(:quote_parameters) @asset.quote_parameters.should respond_to(:<<) @asset.quote_parameters << quote_parameters_1 @asset.quote_parameters << quote_parameters_2 @asset.save.should == true asset_reloaded = Asset.find(@asset.id) asset_reloaded.quote_parameters.map { |p| p.term }.sort.should == [ 36, 48 ] end end Regardless of whether this is a good way to spec the association or (probably) not, it fails on "@asset.save.should == true" with this error: should have many quote parameters PGError: ERROR: null value in column "provider_id" violates not-null constraint : INSERT INTO products ("name", "provider_id", "default_term", "maximum_resolicitation_period", "type", "gap_cover_type_id", "created_at") VALUES(''Product1'', NULL, NULL, NULL, NULL, NULL, ''2007-03-26 14:42:29.872399'') However the probably is actually caused by the first line of the setup, which is missing a mandatory parameter (using validations): @provider = Provider.create(:name => "Provider1", :external_identifier => "external-id") (I was using "new" but changed it to "create" to highlight the issue) Why would this not fail sooner? Thanks Ashley
aslak hellesoy
2007-Mar-26 14:48 UTC
[rspec-users] Failure creating model in spec setup not reported?
On 3/26/07, Ashley Moran <work at ashleymoran.me.uk> wrote:> Hi > > I''ve just tracked down a wierd error that AFAICT is caused by an > error not being raised in the setup: > > context "An Asset" do > setup do > @provider = Provider.create(:name => "Provider1") > @product = Product.new(:name => "Product1", :provider => > @provider) > @applicant = Applicant.new(:first_name => "Fred", :last_name > => "Flinstone", :email => "fred at flinstone.com") > > @asset = Asset.new(:value => BigDecimal("250")) > end > > specify "should have many quote parameters" do > @asset.applicant = @applicant > > quote_parameters_1 = QuoteParameters.new(:term => > 36, :applicant => @applicant, :product => @product) > quote_parameters_2 = QuoteParameters.new(:term => > 48, :applicant => @applicant, :product => @product) > > @asset.should respond_to(:quote_parameters) > @asset.quote_parameters.should respond_to(:<<) > @asset.quote_parameters << quote_parameters_1 > @asset.quote_parameters << quote_parameters_2 > > @asset.save.should == true > > asset_reloaded = Asset.find(@asset.id) > asset_reloaded.quote_parameters.map { |p| > p.term }.sort.should == [ 36, 48 ] > end > end > > Regardless of whether this is a good way to spec the association or > (probably) not, it fails on "@asset.save.should == true" with this > error: > should have many quote parameters > PGError: ERROR: null value in column "provider_id" violates not-null > constraint > : INSERT INTO products ("name", "provider_id", "default_term", > "maximum_resolicitation_period", "type", "gap_cover_type_id", > "created_at") VALUES(''Product1'', NULL, NULL, NULL, NULL, NULL, > ''2007-03-26 14:42:29.872399'') > > > However the probably is actually caused by the first line of the > setup, which is missing a mandatory parameter (using validations): > > @provider = Provider.create(:name => > "Provider1", :external_identifier => "external-id") > > (I was using "new" but changed it to "create" to highlight the issue) > > Why would this not fail sooner? >Sounds like a Rails question. Can you (by running an equivalent Test::Unit test) confirm that this is really RSpec related and not Rails related? Aslak> > Thanks > Ashley > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Ashley Moran
2007-Mar-26 15:11 UTC
[rspec-users] Failure creating model in spec setup not reported?
On 26 Mar 2007, at 15:48, aslak hellesoy wrote:> Sounds like a Rails question. > > Can you (by running an equivalent Test::Unit test) confirm that this > is really RSpec related and not Rails related? > > AslakIt''s ok, me being an idiot. AR::Base.create fails silently. I''d need to use create! to see that error... sorry for the noise