# Can one test manual transactions in Rspec/UnitTest noting the testing framework wraps its DB work in

**URL:** <https://www.ruby-forum.com/t/can-one-test-manual-transactions-in-rspec-unittest-noting-the-testing-framework-wraps-its-db-work-in/157663>\
**Category:** Rails\
**Created:** [January 14, 2009, 8:28am UTC](https://www.ruby-forum.com/t/can-one-test-manual-transactions-in-rspec-unittest-noting-the-testing-framework-wraps-its-db-work-in/157663 "2009-01-14T08:28:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [January 14, 2009, 8:28am UTC](https://www.ruby-forum.com/t/can-one-test-manual-transactions-in-rspec-unittest-noting-the-testing-framework-wraps-its-db-work-in/157663/1 "2009-01-14T08:28:13Z")

</div>

Hi,

Just wondering, can one test manual transactions in Rspec/UnitTest  
noting  
the testing framework wraps its DB work in a transaction & mysql doesn’t  
allow nested transactions?

–  
Greg  
[http://blog.gregnet.org/](http://blog.gregnet.org/)

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [January 15, 2009, 7:23pm UTC](https://www.ruby-forum.com/t/can-one-test-manual-transactions-in-rspec-unittest-noting-the-testing-framework-wraps-its-db-work-in/157663/2 "2009-01-15T19:23:51Z")

</div>

On Wed, Jan 14, 2009 at 1:27 AM, Greg H.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> Just wondering, can one test manual transactions in Rspec/UnitTest noting  
> the testing framework wraps its DB work in a transaction & mysql doesn’t  
> allow nested transactions?

Wrapping code examples (in rspec) or test methods (in t/u) in a  
transaction is the default behavior, but is easily turned off with  
config.transactional\_fixtures = false.

The name transactional\_fixtures is a bit misleading because its really  
about wrapping each method in a transaction whether you’re using  
fixtures or not.

If you do turn this off, however, you’ll want some code to truncate  
the DB after each example (after(:each) in rspec, teardown in  
test/unit) to avoid leaking state across examples.

HTH,  
David

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [January 15, 2009, 9:55pm UTC](https://www.ruby-forum.com/t/can-one-test-manual-transactions-in-rspec-unittest-noting-the-testing-framework-wraps-its-db-work-in/157663/3 "2009-01-15T21:55:09Z")

</div>

actually what I really want would be to turn it off on just some tests,  
i.e.  
the ones that are going to be doing tests relating to transactions and  
rollbacks. Don’t suppose you know if this is possible?  
thanks

On Fri, Jan 16, 2009 at 4:23 AM, David C.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> transaction is the default behavior, but is easily turned off with  
> HTH,
> 
> > >
> 
> >

–  
Greg  
[http://blog.gregnet.org/](http://blog.gregnet.org/)

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [January 16, 2009, 1:48am UTC](https://www.ruby-forum.com/t/can-one-test-manual-transactions-in-rspec-unittest-noting-the-testing-framework-wraps-its-db-work-in/157663/4 "2009-01-16T01:48:59Z")

</div>

actually I’m only using specs (rspec)

On Fri, Jan 16, 2009 at 10:43 AM, Frederick C. \<  
removed\_email\_address@domain.invalid\> wrote:

> unit at least) rails will reload fixtures for you between tests.
> 
> > > Hi,
> > 
> > >
> 
> >

–  
Greg  
[http://blog.gregnet.org/](http://blog.gregnet.org/)

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [January 16, 2009, 1:44am UTC](https://www.ruby-forum.com/t/can-one-test-manual-transactions-in-rspec-unittest-noting-the-testing-framework-wraps-its-db-work-in/157663/5 "2009-01-16T01:44:18Z")

</div>

On 15 Jan 2009, at 20:54, Greg H. wrote:

> actually what I really want would be to turn it off on just some  
> tests, i.e. the ones that are going to be doing tests relating to  
> transactions and rollbacks. Don’t suppose you know if this is  
> possible?

It’s a per subclass of Test::Unit::TestCase setting. IIRC (for test/  
unit at least) rails will reload fixtures for you between tests.

Fred
