Is there anyone out there working on something like DBUnit for Ruby?
Looks like ActiveRecords's Fixtures. No?
http://ar.rubyonrails.org/classes/Fixtures.html
Indeed. I'd dare say that AR's Fixtures (ARF) goes beyond the DBUnit on some fronts. For example, the example asserts in the article uses the following form:
EmployeeValueObject vo = facade.getEmployeeBySocialSecNum("333-29-9999");
TestCase.assertEquals("should be Drew", "Drew", vo.getFirstName());
This repeats the testing literals because the original seed data is not available to the code. With ARF, you could just reference the seed data, so that if that you Don't Repeat Yourself unnecessarily:
drew = Employee.find_by_ssn(@emps["drew"]["ssn"])
assert_equals @emps["drew"]["first_name"], drew.first_name
In Rails, we even go one step further. Since you normally have one production database and one (or more) test databases, it can be quite a pain to keep the schemas in sync during development. Imagine that you want to add a birthday field to the employees table. First you'd have to update two schemas in text for your revision control, then you'd have to update the actual databases with the changes. Lot of work.
With Rails, the default Rake action will do the following:
1. Take a snapshot of the current production schema and save it to file (so you can use graphical database tools to update the database, but still have a text-based schema for the version control).
2. Drop the test database
3. Create a fresh test database based on the schema from the production database.
4. Insert all the fixtures before each test case (and purge them afterwards).
With this flow, you can get by solely with editing the production database schema through a graphical tool (I use the excellent CocoaMySQL), running the default rake build, and still get all the benefits of "the long way".
···
--
David Heinemeier Hansson,
http://www.instiki.org/ -- A No-Step-Three Wiki in Ruby
http://www.basecamphq.com/ -- Web-based Project Management
http://www.loudthinking.com/ -- Broadcasting Brain
http://www.nextangle.com/ -- Development & Consulting Services