0

Is it up to me to write my own system, use a 3rd party solution, or does Rails offer a way to separate my test data from my seed data?

I'm aware of seeds.rb, and that it's just like a regular ruby file. I'd like to store seed/fixture data in something like yaml or json, but also to have my test data be randomly generated or purpose generated (to fail) somewhere separate from the seed data.

chrisp
  • 2,181
  • 4
  • 27
  • 35

1 Answers1

0

If you want to define separate seed files for your database, look at this link.

I think what you really want is either fixtures or factories, such as the FactoryGirl Gem.

Factories and fixtures allow you to define sample model data that is independent of your database state and designed for your tests.

For example, if you wanted a fixture to help you test a validation on a User model, you could have the following users.yml file

bob:
  name: bob
  birthday: 1989-11-12

Then, in your test, you could use the fixture:

test "should validate with name" do
  bob = users(:bob)
  assert bob.valid?
end
Community
  • 1
  • 1
marknach
  • 232
  • 2
  • 8
  • Thanks for that link. That's not a complete solution, but it really is super succinct way of handling different environments. I'll play with fixtures too. Thanks! – chrisp Dec 17 '13 at 19:23