# Hash fixture access broken in functional test

**URL:** <https://www.ruby-forum.com/t/hash-fixture-access-broken-in-functional-test/52867>\
**Category:** Rails\
**Created:** [January 19, 2006, 9:16pm UTC](https://www.ruby-forum.com/t/hash-fixture-access-broken-in-functional-test/52867 "2006-01-19T21:16:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dandante](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9fc29f/32.png) [@dandante](https://www.ruby-forum.com/u/dandante)\
**Post date:** [January 19, 2006, 9:16pm UTC](https://www.ruby-forum.com/t/hash-fixture-access-broken-in-functional-test/52867/1 "2006-01-19T21:16:08Z")

</div>

I have a functional test class that uses the “topics” fixture. I  
verified that the fixture is loaded into the database by doing this:  
assert\_equal 2, Topic.find\_all.size

So I should have an instance variable called @topics and instance  
variables for each of the rows in the fixture, in this case, @first and  
@another. But all those variables are nil inside my test method.

Is that convenience only available in unit tests? It is equally useful  
in functional tests. Or is there some other problem? Thanks…

---

<div class="post-metadata">

**Author:** ![dandante](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9fc29f/32.png) [@dandante](https://www.ruby-forum.com/u/dandante)\
**Post date:** [January 20, 2006, 8:42pm UTC](https://www.ruby-forum.com/t/hash-fixture-access-broken-in-functional-test/52867/2 "2006-01-20T20:42:38Z")

</div>

Dan T. wrote:

> I have a functional test class that uses the “topics” fixture. I  
> verified that the fixture is loaded into the database by doing this:  
> assert\_equal 2, Topic.find\_all.size
> 
> So I should have an instance variable called @topics and instance  
> variables for each of the rows in the fixture, in this case, @first and  
> @another. But all those variables are nil inside my test method.
> 
> Is that convenience only available in unit tests? It is equally useful  
> in functional tests. Or is there some other problem? Thanks…

Looks like this doesn’t work in unit tests either. What gives? The rails  
book says I should be able to do this, and I definitely have a more  
recent version of rails and ruby than they did when writing that  
book…

---

<div class="post-metadata">

**Author:** ![dandante](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9fc29f/32.png) [@dandante](https://www.ruby-forum.com/u/dandante)\
**Post date:** [January 20, 2006, 9:46pm UTC](https://www.ruby-forum.com/t/hash-fixture-access-broken-in-functional-test/52867/3 "2006-01-20T21:46:08Z")

</div>

Dan T. wrote:

> Dan T. wrote:
> 
> > I have a functional test class that uses the “topics” fixture. I  
> > verified that the fixture is loaded into the database by doing this:  
> > assert\_equal 2, Topic.find\_all.size
> > 
> > So I should have an instance variable called @topics and instance  
> > variables for each of the rows in the fixture, in this case, @first and  
> > @another. But all those variables are nil inside my test method.
> > 
> > Is that convenience only available in unit tests? It is equally useful  
> > in functional tests. Or is there some other problem? Thanks…
> 
> Looks like this doesn’t work in unit tests either. What gives? The rails  
> book says I should be able to do this, and I definitely have a more  
> recent version of rails and ruby than they did when writing that  
> book…

Things changed just slightly since the book: here is a quote from  
[http://www.ruby-forum.com/topic/50061#17690](http://www.ruby-forum.com/topic/50061#17690)

> The book is awesome, but beware that the section on accessing \> fixture data in unit tests is broken since 1.0 came around. Found \> that out the hard way the other night. \> \> You used to be able to access fixture data like @my\_product, but \> now it’s like products(:my\_product)

HTH,  
Keith

---

<div class="post-metadata">

**Author:** ![dandante](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9fc29f/32.png) [@dandante](https://www.ruby-forum.com/u/dandante)\
**Post date:** [January 20, 2006, 9:47pm UTC](https://www.ruby-forum.com/t/hash-fixture-access-broken-in-functional-test/52867/4 "2006-01-20T21:47:22Z")

</div>

Keith L. wrote:

> Dan T. wrote:
> 
> > Dan T. wrote:
> > 
> > > I have a functional test class that uses the “topics” fixture. I  
> > > verified that the fixture is loaded into the database by doing this:  
> > > assert\_equal 2, Topic.find\_all.size
> > > 
> > > So I should have an instance variable called @topics and instance  
> > > variables for each of the rows in the fixture, in this case, @first and  
> > > @another. But all those variables are nil inside my test method.
> > > 
> > > Is that convenience only available in unit tests? It is equally useful  
> > > in functional tests. Or is there some other problem? Thanks…
> > 
> > Looks like this doesn’t work in unit tests either. What gives? The rails  
> > book says I should be able to do this, and I definitely have a more  
> > recent version of rails and ruby than they did when writing that  
> > book…
> 
> Things changed just slightly since the book: here is a quote from  
> [Rails 1.0 - Agile book still good? - Rails - Ruby-Forum](http://www.ruby-forum.com/topic/50061#17690)
> 
> > The book is awesome, but beware that the section on accessing \> fixture data in unit tests is broken since 1.0 came around. Found \> that out the hard way the other night. \> \> You used to be able to access fixture data like @my\_product, but \> now it’s like products(:my\_product)
> 
> HTH,  
> Keith

From the same post:  
This is simply an option which was on by default and was turned off by  
default but it is still a valid way to access fixture data, all you  
have to do is change test\_helper.rb (if you want it for all tests, or  
add the following line at the beginning of the testcase where you want  
it :

self.use\_instantiated\_fixtures = true

Keith (again…)

---

<div class="post-metadata">

**Author:** ![dandante](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9fc29f/32.png) [@dandante](https://www.ruby-forum.com/u/dandante)\
**Post date:** [January 20, 2006, 9:51pm UTC](https://www.ruby-forum.com/t/hash-fixture-access-broken-in-functional-test/52867/5 "2006-01-20T21:51:06Z")

</div>

Keith L. wrote:

> Things changed just slightly since the book: here is a quote from  
> [Rails 1.0 - Agile book still good? - Rails - Ruby-Forum](http://www.ruby-forum.com/topic/50061#17690)

Thanks. That works. Hope they come out with that PDF of  
revisions…
