# Rspec fixtures stay in the test db - is this right?

**URL:** <https://www.ruby-forum.com/t/rspec-fixtures-stay-in-the-test-db-is-this-right/128396>\
**Category:** Rails\
**Created:** [February 7, 2008, 10:51am UTC](https://www.ruby-forum.com/t/rspec-fixtures-stay-in-the-test-db-is-this-right/128396 "2008-02-07T10:51:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [February 7, 2008, 10:51am UTC](https://www.ruby-forum.com/t/rspec-fixtures-stay-in-the-test-db-is-this-right/128396/1 "2008-02-07T10:51:28Z")

</div>

I have some fixtures set up to put a few records in some of my tables.  
In some of my rspec describe blocks, i’m _not_ calling the fixtures, and  
expecting the tables to be empty. But they’re not - the fixture data is  
in there.

Am i using fixtures wrongly? I thought that the db was wiped at the  
start of every test and the fixtures were only added if asked for. Is  
that not the case? I’m new to rspec and can’t find much about fixtures  
in the documentation.

thanks  
max

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [March 25, 2008, 8:30pm UTC](https://www.ruby-forum.com/t/rspec-fixtures-stay-in-the-test-db-is-this-right/128396/2 "2008-03-25T20:30:08Z")

</div>

Are you by any chance running this with a Sqlite db? I am running into  
the same problem and I vaguely remember that Sqlite does not support  
transactions. Which is set in my spec\_helper.rb. Perhaps that throws  
Rspec off.

With kind regards,  
Harm

On Feb 7, 10:51 am, Max W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [March 28, 2008, 4:38pm UTC](https://www.ruby-forum.com/t/rspec-fixtures-stay-in-the-test-db-is-this-right/128396/3 "2008-03-28T16:38:11Z")

</div>

On Thu, Feb 7, 2008 at 5:51 AM, Max W.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have some fixtures set up to put a few records in some of my tables.  
> In some of my rspec describe blocks, i’m _not_ calling the fixtures, and  
> expecting the tables to be empty. But they’re not - the fixture data is  
> in there.
> 
> Am i using fixtures wrongly? I thought that the db was wiped at the  
> start of every test and the fixtures were only added if asked for. Is  
> that not the case? I’m new to rspec and can’t find much about fixtures  
> in the documentation.

RSpec just wraps Rails testing infrastructure, so you should see the  
same behaviour in rspec or test/unit.

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [March 28, 2008, 4:46pm UTC](https://www.ruby-forum.com/t/rspec-fixtures-stay-in-the-test-db-is-this-right/128396/4 "2008-03-28T16:46:32Z")

</div>

David C. wrote:

> On Thu, Feb 7, 2008 at 5:51 AM, Max W.  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > I have some fixtures set up to put a few records in some of my tables.  
> > In some of my rspec describe blocks, i’m _not_ calling the fixtures, and  
> > expecting the tables to be empty. But they’re not - the fixture data is  
> > in there.
> > 
> > Am i using fixtures wrongly? I thought that the db was wiped at the  
> > start of every test and the fixtures were only added if asked for. Is  
> > that not the case? I’m new to rspec and can’t find much about fixtures  
> > in the documentation.
> 
> RSpec just wraps Rails testing infrastructure, so you should see the  
> same behaviour in rspec or test/unit.

Hi David

You actually answered this question in another mailing list a while ago

- it was because my fixture data was being loaded in a before :all  
rather than before :each - and so couldn’t be rolled back out of  
existence when the describe block finished. So, every time i ran the  
test the data was stacking up. Just in case anyone else was wondering  
(sorry, i should have replied to this post myself once i found the  
answer).

thanks  
max

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [March 28, 2008, 4:51pm UTC](https://www.ruby-forum.com/t/rspec-fixtures-stay-in-the-test-db-is-this-right/128396/5 "2008-03-28T16:51:24Z")

</div>

On Fri, Mar 28, 2008 at 11:46 AM, Max W.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > Am i using fixtures wrongly? I thought that the db was wiped at the  
> > > start of every test and the fixtures were only added if asked for. Is  
> > > that not the case? I’m new to rspec and can’t find much about fixtures  
> > > in the documentation.
> > 
> > RSpec just wraps Rails testing infrastructure, so you should see the  
> > same behaviour in rspec or test/unit.
> 
> Hi David
> 
> You actually answered this question in another mailing list a while ago

Ah - difficult to keep track of who is who sometimes! Glad you got it  
resolved.

Cheers,  
David

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [August 20, 2008, 8:27am UTC](https://www.ruby-forum.com/t/rspec-fixtures-stay-in-the-test-db-is-this-right/128396/6 "2008-08-20T08:27:54Z")

</div>

Max:

How are you loading your fixture data from within a before(:each)  
block? The “fixtures” method isn’t available within that block. Are  
you doing it manually somehow?

Ian

On Mar 28, 8:46 am, Max W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [August 20, 2008, 10:16am UTC](https://www.ruby-forum.com/t/rspec-fixtures-stay-in-the-test-db-is-this-right/128396/7 "2008-08-20T10:16:34Z")

</div>

Ian Lesperance wrote:

> Max:
> 
> How are you loading your fixture data from within a before(:each)  
> block? The “fixtures” method isn’t available within that block. Are  
> you doing it manually somehow?
> 
> Ian
> 
> On Mar 28, 8:46ï¿½am, Max W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

What i’m doing _now_ is having the fixtures call as the first line in a  
describe block. I can’t remember what i was doing all that time ago  
(only march? seems like years), probably something dumb 🙂
