[rspec-users] [newbie] rspec, validations and factory_girl

Lille lille.penguini at gmail.com
Mon Jul 26 12:34:49 EDT 2010


Hi,

class B < ActiveRecord::Base
  belongs_to :a
  validates_numericality_of :some_attribute, :greater_than =>
0, :allow_blank=>true

  def some_attribute
      a.numeric_attr * read_attribute(:some_attribute)
  end
  ...

If I create an instance of my class B in rspec with factory_girl w.out
a parent (but not required!) instance of class A, I get the following
error: "undefined method `numeric_attr' for nil:NilClass".

Why? Is this an apparent idiosyncrasy of using rspec and factory_girl
together?

Thanks,

Lille


More information about the rspec-users mailing list