[rspec-users] Loading numerous data structures from YAML files

Paul Hinze paul.t.hinze at gmail.com
Mon Jan 4 21:58:49 EST 2010

Peter Hicks <peter.hicks at poggs.co.uk> on 2010-01-02 at 16:13:
> Hi Phillip
> Phillip Koebbe wrote:
>> Have you read about fixtures? It sounds like just what you're looking
>> for.
> I'm using fixtures already - they're great.  I can't find a way to load a 
> specific fixture in to a table.  If I could do that, I could load a set of 
> data, run the code, check the results, and repeat again for the next test.

My group has mostly moved off fixtures towards factory_girl, but we
still depend on a couple of tables' worth of data to get a basic
environment set up for some of our cucumber features.

For this I use the little-documented method that is used internally by
ActiveRecord::Fixtures called 'create_fixtures'.

> create_fixtures(fixtures_directory, table_names, class_names = {})

Since it accepts a directory first, you can store the YAML files
wherever you'd like, and load them when you choose -- in
spec/spec_helper.rb or in individual example groups if you wanted.

Here's a snippet from my features/support/env.rb to give you an idea:

  Fixtures.create_fixtures('test/fixtures', 'roles')
  Fixtures.create_fixtures('test/fixtures', 'role_members')
  Fixtures.create_fixtures('test/fixtures', 'rights')

Hope this helps!


More information about the rspec-users mailing list