#42 √ committed
Bruce Williams

Support multiple setup/teardown blocks per context

Reported by Bruce Williams | June 25th, 2008 @ 09:51 PM

Thanks for a great, simple testing framework.

I've added support for multiple setup/teardown blocks per context (bruce/shoulda master 32aa22d978), which allows reuse of code across contexts without fear of conflicting with any setup/teardown already defined. Tests included. I sent a pull request before noticing the contribution guidelines; sorry -- here's my ticket!

http://github.com/bruce/shoulda/...

Comments and changes to this ticket

  • Chris O'Sullivan

    Chris O'Sullivan June 26th, 2008 @ 04:44 AM

    Hey Bruce,

    Could you please provide some use cases as to how this works?

    Thanks,

    Chris

  • Tammer Saleh

    Tammer Saleh June 26th, 2008 @ 10:12 AM

    • → State changed from “new” to “open”

    Bruce,

    Yeah, this is something that one of my coworkers has been asking for. I'll add it in some time today.

    Chris: It's primarily useful when writing a context macro that should have some setup in it, but also allows for the macro caller to write some setup code as well. I'll add some documentation to clear that up.

    Cheers,

    Tammer

  • Bruce Williams

    Bruce Williams June 26th, 2008 @ 11:32 AM

    Chris, attached an example for you (it's pretty contrived, I'll admit). Just drop it into test/other on my branch.

    Tammer, thanks. Also, if there's a more Shoulda-idiomatic way of extending functionality in Context than how I'm doing it in the attached example, please let me know; it's possible I didn't read through enough of the Rails-specific code to run across the best method.

    Cheers,

    Bruce

  • Ryan McGeary

    Ryan McGeary June 26th, 2008 @ 03:11 PM

    Funny. I just had a need for this and was about to work on a patch myself. Glad I checked here first.

    Bruce, Tammer, Maybe I'm over thinking this but shouldn't the teardown blocks be run in reverse order?

    I added a comment to Bruce's commit:

    http://github.com/bruce/shoulda/...

  • Tammer Saleh

    Tammer Saleh June 26th, 2008 @ 03:41 PM

    • → State changed from “open” to “committed”
  • Tammer Saleh

    Tammer Saleh June 26th, 2008 @ 03:41 PM

    I've reversed the order of the teardown blocks.

    Thanks for the patch, bruce.

  • Bruce Williams

    Bruce Williams June 26th, 2008 @ 06:29 PM

    No problem, my pleasure... and the reverse ordering definitely makes sense; I was thinking about that myself this afternoon ;-)

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »