On Tuesday, April 24, 2012 at 11:11 AM, Rodrigo Rosenfeld Rosas wrote: > No, I start my specs with some populated data for some tables that shouldn't > change unless in some specific examples, but I'd like them to rollback to the > original state at the end of the examples. I do really want to use savepoints > instead of a truncate strategy or I'd be already using DatabaseCleaner for > that. > > Your suggested approach wouldn't work pretty well as there are some database > constraints that would require a certain order in the tables as well. This is > pretty hard to maintain anyway and it is much slower than "truncate table1, > table2, ...". Rodrigo,
It sounds like you need several "kinds" of tests. The speedy unit tests can be done to exercise your code, objects, etc without the use of the DB and some integration tests. To me, the tests you're talking about here are clearly integration tests since you are writing data to the database. It also sounds like you have some order dependent things happening. The combination is difficult because it is a bad practice (in the eyes of most test/spec advocates). Your tests really should be able to run in any order - from expectation to expectation. > > > > Yes, I've realized that too. This makes it really hard to me to manually > create the savepoints by myself while still using Sequel transaction support > in the around(:each) block. These save points could be emulated by creating fixtures (or factory objects) that simulate things in the correct state then testing them. If you are trying to test state/savepoint transitions then start with an object in state #1, move it to state #2 and then test. Going from #1 to #2 to #3 probably isn't a good idea in a spec environment. > Could you please give me some hint on how to achieve that with Sequel? Again, the friction you are feeling is mostly likely due to straying from the Golden Path(™) in tests/specs. It might be enlightening if you posted a gist with your intended usage and perhaps we could help from there. Don @elskwid -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.
