I would like to add TDD/BDD to my rails app, but it uses MongoDB for storing the data.
So my question is, does there exist gems that can somehow simulate MongoDB or some other means to use TDD/BDD in MongoDB heavy rails apps?
When you are writing acceptance tests it is completely fine to use a real data base. Acceptance tests are end-to-end and are supposed to test the behavior of your whole system after all.
However, when writing simple unit tests for classes that modify some data and need to save it you don't want to rely on a concrete database. Most of your unit tests won't even need any persistent data. You will need to tell some module 'save that', 'update this', 'delete that', sure, but there's no need to permanently save stuff. So why go through the trouble of creating a data base? Instead you can create a mock of your data mapper:
The DataMapperMock
will just store anything you save/update in memory. So when you want to test if your application created or updated objects correctly you can just set up your application with a DataMapperMock
instead of the real thing and ask if it has received these objects. So in the end mocking a database is pretty easy to do and doesn't really require any special framework magic. That applies only to tests that don't require persistent data. But even for that the solution wouldn't be too hard. Just create another mock that saves/reads text files instead of using a data base. That will most likely be good enough for your tests, since you usually don't end up saving lots of data in a unit test.