# Fixtures just Do Not Work for Me

**URL:** <https://www.ruby-forum.com/t/fixtures-just-do-not-work-for-me/55749>\
**Category:** Rails\
**Created:** [March 23, 2006, 4:15pm UTC](https://www.ruby-forum.com/t/fixtures-just-do-not-work-for-me/55749 "2006-03-23T16:15:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![thiagoalessio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/d6d6ee/32.png) [@thiagoalessio](https://www.ruby-forum.com/u/thiagoalessio)\
**Post date:** [March 23, 2006, 4:15pm UTC](https://www.ruby-forum.com/t/fixtures-just-do-not-work-for-me/55749/1 "2006-03-23T16:15:53Z")

</div>

Hello,

I have been struggling to get fixtures to work here with no success.  
They just Do Not Work For Me ™.

I have created a model named Headline with the `generate’ script and  
modified the test/fixtumes/headlines.yml as follows

* * *

gita:  
id: 1  
author: raulseixas  
title: gita  
happened\_at: 2005-01-01 00:00:00  
description: gita

```
           This is the CD reissue of the 1974 album and second solo 

```

release  
by Raul Seixas, an important figure of Brazilian rock.  
Acid  
critic of establishment, he pardodies several figures of  
Brazilian showbiz in the rocking “Super-Heróis.”

# more fixtures here

* * *

My database table has columns named id, author, title, happened\_at and  
description as expected. My headline\_test file is as follows

* * *

class HeadlineTest \< Test::Unit::TestCase  
fixtures :headlines

```
def test_fixture
    h = @headlines['gita']

    puts h.title
end

```

## end

When I call the test with `ruby test/unit/headline\_test’, I get the  
following output:

* * *

1. Error:  
test\_fixture(HeadlineTest):  
NoMethodError: You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occured while evaluating nil.[]  
test/unit/headline\_test.rb:25:in `test\_fixture’

* * *

The call to the `fixtures’ methods is supposed to initalize the  
@headlines instance variable, isn’t it? I can’t see where is my  
mistake.

Cheers,

Thiago A.

---

<div class="post-metadata">

**Author:** ![thiagoalessio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/d6d6ee/32.png) [@thiagoalessio](https://www.ruby-forum.com/u/thiagoalessio)\
**Post date:** [March 23, 2006, 4:24pm UTC](https://www.ruby-forum.com/t/fixtures-just-do-not-work-for-me/55749/2 "2006-03-23T16:24:11Z")

</div>

Thiago A. wrote:

> The call to the `fixtures’ methods is supposed to initalize the  
> @headlines instance variable, isn’t it? I can’t see where is my  
> mistake.  
> The syntax for getting at fixtures changed between the publication of  
> AWDWR and Rails 1.0 - I expect that’s what’s bitten you. Try  
> headlines(‘gita’) instead of @headlines[‘gita’].

---

<div class="post-metadata">

**Author:** ![thiagoalessio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/d6d6ee/32.png) [@thiagoalessio](https://www.ruby-forum.com/u/thiagoalessio)\
**Post date:** [March 23, 2006, 5:42pm UTC](https://www.ruby-forum.com/t/fixtures-just-do-not-work-for-me/55749/3 "2006-03-23T17:42:56Z")

</div>

On 3/23/06, Alex Y. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The syntax for getting at fixtures changed between the publication of  
> AWDWR and Rails 1.0 - I expect that’s what’s bitten you. Try  
> headlines(‘gita’) instead of @headlines[‘gita’].

Thanks, Alex. Works perfectly now.

–  
Thiago A.

---

<div class="post-metadata">

**Author:** ![thiagoalessio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/d6d6ee/32.png) [@thiagoalessio](https://www.ruby-forum.com/u/thiagoalessio)\
**Post date:** [March 23, 2006, 6:14pm UTC](https://www.ruby-forum.com/t/fixtures-just-do-not-work-for-me/55749/4 "2006-03-23T18:14:50Z")

</div>

Thiago A. wrote:

> Is this outdated too? Is there any other place that I can go for docs?
> 
> [http://api.rubyonrails.org/classes/Fixtures.html](http://api.rubyonrails.org/classes/Fixtures.html)

It’s not actually outdated per se - the defaults just changed. You can  
actually turn the old behaviour back on. There’s an explanation of what  
changed (and why) here:

[http://clarkware.com/cgi/blosxom/2005/10/24](http://clarkware.com/cgi/blosxom/2005/10/24)

---

<div class="post-metadata">

**Author:** ![thiagoalessio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/d6d6ee/32.png) [@thiagoalessio](https://www.ruby-forum.com/u/thiagoalessio)\
**Post date:** [March 23, 2006, 6:07pm UTC](https://www.ruby-forum.com/t/fixtures-just-do-not-work-for-me/55749/5 "2006-03-23T18:07:57Z")

</div>

On 3/23/06, Alex Y. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The syntax for getting at fixtures changed between the publication of  
> AWDWR and Rails 1.0 - I expect that’s what’s bitten you. Try  
> headlines(‘gita’) instead of @headlines[‘gita’].

Is this outdated too? Is there any other place that I can go for docs?

[http://api.rubyonrails.org/classes/Fixtures.html](http://api.rubyonrails.org/classes/Fixtures.html)

Regards,

Thiago A.

---

<div class="post-metadata">

**Author:** ![thiagoalessio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/d6d6ee/32.png) [@thiagoalessio](https://www.ruby-forum.com/u/thiagoalessio)\
**Post date:** [March 23, 2006, 6:24pm UTC](https://www.ruby-forum.com/t/fixtures-just-do-not-work-for-me/55749/6 "2006-03-23T18:24:41Z")

</div>

On 3/23/06, Alex Y. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> It’s not actually outdated per se - the defaults just changed. You can  
> actually turn the old behaviour back on. There’s an explanation of what  
> changed (and why) here:
> 
> [http://clarkware.com/cgi/blosxom/2005/10/24](http://clarkware.com/cgi/blosxom/2005/10/24)

I need to know how many fixtures are defined in the fixture file.  
Having read this I went like

* * *

class MyControllerTest \< Test::Unit::TestCase

```
self.use_instantiated_fixtures = true
fixtures :headlines

def test_full_loaded
    get :show_all_headlines
    assert_equal @headlines.size, assigns(:headline).size
end

```

## end

Would there be a more recommended way of achieving this? Can I get the  
number o fixtures loaded without using instantiated fixtures?

Thanks,

Thiago A.

---

<div class="post-metadata">

**Author:** ![thiagoalessio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/d6d6ee/32.png) [@thiagoalessio](https://www.ruby-forum.com/u/thiagoalessio)\
**Post date:** [March 23, 2006, 6:38pm UTC](https://www.ruby-forum.com/t/fixtures-just-do-not-work-for-me/55749/7 "2006-03-23T18:38:26Z")

</div>

On 3/23/06, Alex Y. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> In this case, I think you could do Headlines.count.

Thanks for this one. I think I had gone into tunnel mode and looking  
on the woring place.

Cheers,

Thiago A.

---

<div class="post-metadata">

**Author:** ![thiagoalessio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/d6d6ee/32.png) [@thiagoalessio](https://www.ruby-forum.com/u/thiagoalessio)\
**Post date:** [March 23, 2006, 6:29pm UTC](https://www.ruby-forum.com/t/fixtures-just-do-not-work-for-me/55749/8 "2006-03-23T18:29:28Z")

</div>

Thiago A. wrote:

> Would there be a more recommended way of achieving this? Can I get the  
> number o fixtures loaded without using instantiated fixtures?

In this case, I think you could do Headlines.count.
