[rspec-users] fixtures and associations

Pat Maddox pergesu at gmail.com
Wed Dec 17 19:14:56 EST 2008


On Wed, Dec 17, 2008 at 2:13 PM, Daniel Lopes <danielvlopes at gmail.com> wrote:
> Hello Pat, even I load all my fixtures it still not reading anything from
> users.yml ...
> I will look at factory_girl but before I need understand what happening.
> I try this:
> require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
> describe Tenant do
>   fixtures :properties, :users , :owners
>   def create_tenant(options = {})
>     record = Tenant.create({
>       :property => properties(:two),
>       :renters => "value for renters",
>       :guarantor => "value for guarantor",
>       :contact_name => "value for contact_name",
>       :contact_phone => "value for contact_phone",
>       :contact_email => "teste at hosttest.com",
>       :end_date => Date.today,
>       :beginning_date => Date.today,
>       :initial_value => "9.99"
>     }.merge(options))
>   end
>
>   before(:each) do
>     @tenant = create_tenant
>   end
>
>   it "should create a new instance given valid attributes" do
>     p properties(:two).errors
>     properties(:two).should be_valid
>     # @tenant.errors.should be_empty
>   end
> end

What error are you getting now?  Please post whatever error you're
experiencing...when we change this code, I expect a different error,
and would not know what it is.  If it's the same, that's strange.

Also, I noticed you have
p properties(:two).errors
properties(:two).should be_valid

That's not going to show you anything, because errors don't get added
until you call #valid?  So change that to

properties(:two).valid?
p properties(:two).errors

Pat


More information about the rspec-users mailing list