Peter Hicks
2010-Jan-02 11:17 UTC
[rspec-users] Loading numerous data structures from YAML files
All, 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? Best wishes, Peter
Phillip Koebbe
2010-Jan-02 22:02 UTC
[rspec-users] Loading numerous data structures from YAML files
On Jan 2, 5:17?am, Peter Hicks <peter.hi... at poggs.co.uk> wrote:> > 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, > > PeterHi Peter, Have you read about fixtures? It sounds like just what you''re looking for. Peace, Phillip
Peter Hicks
2010-Jan-02 22:12 UTC
[rspec-users] Loading numerous data structures from YAML files
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. Peter
Paul Hinze
2010-Jan-05 02:58 UTC
[rspec-users] Loading numerous data structures from YAML files
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 = {})http://apidock.com/rails/Fixtures/create_fixtures/class 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! Paul