I am writing specs for some multi-stage tests which require a lot of
input data.
A simplified overview of the tests is as follows:
Provide list of network interfaces, confirm they are added to the
database
Provide list of network interfaces as above, but with one entry
added, and confirm this entry is added to the database
Provide list of network interfaces as above, but with a different
entry removed, and confirm this entry is added to the database
I want to isolate the test data from the specs themselves for
cleanliness, and I am thinking of putting them in YAML files.
How best should I tackle this? Where should I put the YAML files and is
there any functionality in RSpec that will help? Should I roll my own
“load test data” code and present that to the test code?
How best should I tackle this? Where should I put the YAML files and is
there any functionality in RSpec that will help? Should I roll my own
“load test data” code and present that to the test code?
Best wishes,
Peter
Hi Peter,
Have you read about fixtures? It sounds like just what you’re looking
for.
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.
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’.
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: