[LRUG] Handling opening and closing of transactions manually in ActiveRecord
Matthew Willson
matthew at playlouder.com
Fri Oct 8 04:52:40 PDT 2010
> Aah interesting! sadly it's not a technique that's transferrable over
> to rspec / AR, but very elegant nonetheless. I recently switched back
> to using test/unit and stories from rspec and cucumber for a personal
> project recently, and this nicely illustrates one of the reasons why -
> the syntax, while being a bit more verbose than rspec's, actually
> allows you to do things like this in a simple ruby-ish way, rather
> than messing around with the implementation of their DSL.
Ah, sorry I missed the point too and didn't realise it was the before_*all* hooks you wanted wrapped!
If you want a dirty-but-clever-hack solution, you could probably do something with continuations (in MRI 1.8) or coroutines (ie Fibers in 1.9) to wrap something in a block based only on separate before/after callbacks :) [I now see someone beat me to that, heh]
But yeah I'm with you on the rspec thing. I like test/unit because with it, you use normal ruby OO concepts (subclasses, mixins, overriding methods, super calls etc) to achieve code re-use, rather than having to figure out how the framework has reinvented these things in its own DSL, in a funky, not-quite-the-same-as-what-you-expect-but-near-enough-to-initially-pass-for-it way :)
Then again I like the rspec syntax a lot better. test/spec ( http://test-spec.rubyforge.org/test-spec/ ) is an attempt to provide the best of both worlds, by adding a thin-ish rspec-like "syntactic sugar" layer on top of test/unit. Although it could use a bit of love of late, I like the philosophy.
-Matt
More information about the Chat
mailing list