We are a user experience design and software development firm
Hire us to design your site, build your application, serve billions of users and solve real problems.
We have been using fixture_replacement2 on some of our Ruby on Rails projects. I am writing an internal application and finally switched over from using fixtures. It took a bit of time to get the tests that I had written modified to stop using the fixture data, but now I am completely fixture free. The tests are a lot easier to write, and I created a few helper methods that setup common datasets. This way, I can call a setup method to configure my data, and then - it's all good. At first I called the method test_data_blah, and was wondering why I was getting an error running any test, so now it's called data_blah. Doh!
At first I didn't like the fact that I needed to explicitly create the data for what I was working on, but then I realized that (especially for unit tests) you don't need much dependent data; usually it's one or two records. For functional tests, I found that the data setup methods rocked, as I could quickly get the data set up that I needed.I could quickly assert the content of the response, based on the data in my setup. I missed fixtures at first, but now realize that over time, they are a pain.
My unit tests used to take about 5 seconds, now it's around a minute. I am not really happy about this, as I like to run rake before each commit, and I am apparently very impatient. The luxury of fixtures is that it loads the data directly in the database, and skips the model validations and what-not. The transaction is started, each test is run, and then the transaction is rolled back. Now, all of my data setup occurs in the transaction rather than before it.
So, I think I am definitely using the plugin, but need to make sure not to create any more data than necessary for the tests I'm writing. I guess I miss the speed of fixtures, but the benefits from the plugin seem to outweigh my impatience. At first it seemed that fixtures were the way to go, but the more I use fixture replacement, the more I realize that I don't miss them at all.
Topics: fixture replacement, fixtures, plugin, plugins, Ruby on Rails, Testing
Hire us to design your site, build your application, serve billions of users and solve real problems.