# Unit tests and fixtures

**URL:** <https://www.ruby-forum.com/t/unit-tests-and-fixtures/173711>\
**Category:** Rails\
**Created:** [August 13, 2009, 5:14pm UTC](https://www.ruby-forum.com/t/unit-tests-and-fixtures/173711 "2009-08-13T17:14:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![introvert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c37758/32.png) [@introvert](https://www.ruby-forum.com/u/introvert)\
**Post date:** [August 13, 2009, 5:14pm UTC](https://www.ruby-forum.com/t/unit-tests-and-fixtures/173711/1 "2009-08-13T17:14:26Z")

</div>

Hello

I’m experiencing some problems using rails fixtures with unit tests.

With my version of Ruby I have to define test with the following syntax:

test ‘some test’ do  
assert…  
end

instead of

def test\_some\_test  
assert…  
end

If I try to include/load the fixtures by using:  
fixtures :stories, :votes

after the class definition, I get the following errors:

StandardError: No fixture with name…

What am I doing wrong?  
Is this the latest Ruby test code or am I using some outdated version?  
Is there any place that I could check that (I tried with some googling  
without relevant results)?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![introvert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c37758/32.png) [@introvert](https://www.ruby-forum.com/u/introvert)\
**Post date:** [August 13, 2009, 8:56pm UTC](https://www.ruby-forum.com/t/unit-tests-and-fixtures/173711/2 "2009-08-13T20:56:11Z")

</div>

Aljaz F. wrote:

> With my version of Ruby I have to define test with the following syntax:
> 
> test ‘some test’ do  
> assert…  
> end

What do you mean by this? I don’t think the Ruby version should have  
anything to do with this. What testing framework are you using  
(Test::Unit, Soulda, etc)?

This might affect how you use fixtures, I’m not sure. I use rSpec  
myself. I also tend to avoid fixtures altogether in favor of factories  
(factory\_girl, machinist, etc.).

---

<div class="post-metadata">

**Author:** ![introvert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c37758/32.png) [@introvert](https://www.ruby-forum.com/u/introvert)\
**Post date:** [August 13, 2009, 9:22pm UTC](https://www.ruby-forum.com/t/unit-tests-and-fixtures/173711/3 "2009-08-13T21:22:59Z")

</div>

Robert W. wrote:

> Aljaz F. wrote:
> 
> > With my version of Ruby I have to define test with the following syntax:
> > 
> > test ‘some test’ do  
> > assert…  
> > end
> 
> What do you mean by this? I don’t think the Ruby version should have  
> anything to do with this. What testing framework are you using  
> (Test::Unit, Soulda, etc)?
> 
> This might affect how you use fixtures, I’m not sure. I use rSpec  
> myself. I also tend to avoid fixtures altogether in favor of factories  
> (factory\_girl, machinist, etc.).

I’m using the default one and I’m not yet familiar with all the  
concepts.

---

<div class="post-metadata">

**Author:** ![introvert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c37758/32.png) [@introvert](https://www.ruby-forum.com/u/introvert)\
**Post date:** [August 14, 2009, 12:07am UTC](https://www.ruby-forum.com/t/unit-tests-and-fixtures/173711/4 "2009-08-14T00:07:34Z")

</div>

On Aug 13, 4:14 pm, Aljaz F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> instead of
> 
> def test\_some\_test  
> assert…  
> end

Either syntax works.

> If I try to include/load the fixtures by using:  
> fixtures :stories, :votes

you don’t need that any more - The default test\_helper.rb is set to  
load all fixtures.

Fred

---

<div class="post-metadata">

**Author:** ![introvert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c37758/32.png) [@introvert](https://www.ruby-forum.com/u/introvert)\
**Post date:** [August 14, 2009, 4:59pm UTC](https://www.ruby-forum.com/t/unit-tests-and-fixtures/173711/5 "2009-08-14T16:59:58Z")

</div>

Frederick C. wrote:

> On Aug 13, 4:14ï¿½pm, Aljaz F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > instead of
> > 
> > def test\_some\_test  
> > ï¿½ assert…  
> > end
> 
> Either syntax works.
> 
> > If I try to include/load the fixtures by using:  
> > ï¿½ fixtures :stories, :votes
> 
> you don’t need that any more - The default test\_helper.rb is set to  
> load all fixtures.
> 
> Fred

If I remove the line for including specific fixtures, I still get the  
errors (although the fixtures exist):

1. Error:  
test\_should\_return\_3\_latest\_votes(StoryTest):  
StandardError: No fixture with name ‘first’ found for table ‘stories’

Any idea what could be wrong?

---

<div class="post-metadata">

**Author:** ![introvert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c37758/32.png) [@introvert](https://www.ruby-forum.com/u/introvert)\
**Post date:** [August 14, 2009, 5:09pm UTC](https://www.ruby-forum.com/t/unit-tests-and-fixtures/173711/6 "2009-08-14T17:09:30Z")

</div>

2009/8/14 Aljaz F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > Either syntax works.  
> > errors (although the fixtures exist):
> 
> Â 1) Error:  
> test\_should\_return\_3\_latest\_votes(StoryTest):  
> StandardError: No fixture with name ‘first’ found for table ‘stories’

Have you got a record ‘first:’ in stories.yml? If so check the syntax  
carefully.

Colin

---

<div class="post-metadata">

**Author:** ![introvert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c37758/32.png) [@introvert](https://www.ruby-forum.com/u/introvert)\
**Post date:** [August 17, 2009, 7:47am UTC](https://www.ruby-forum.com/t/unit-tests-and-fixtures/173711/7 "2009-08-17T07:47:43Z")

</div>

You should write  
fixtures :stories, :votes, :first

2009/8/14 Colin L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
