Topic: Declaring dependencies between yml files

I have fixture files for users and countries.

A user belongs_to a country (mandatory association), so my users in the users.yml must associate themselve to a country or otherwise they won't be valid.

In my test cases I use...

  fixtures :countries
  fixtures :users

Unfortunately I forgot to add the countries-fixtures to some unit test, leading to very strange test results (actually to_yaml broke).

So I am wondering if there's some include mechanism in yaml. What I would like to do is declare the dependency to countries.yml in users.yml.

Something like...

import 'countries'

Re: Declaring dependencies between yml files

I usually just load all the fixtures in each test case so I don't have this problem. In edge rails you can do this:

fixtures :all

I don't think this works in 1.2.3 so in that case you could move it into the test_helper:

# in test_helper.rb
fixtures :foo, :bar, :blah

Then you can remove all fixtures declarations in all other tests because they inherit from this and will automatically include the fixtures.

Railscasts - Free Ruby on Rails Screencasts