# Strange Unit Testing error - newbie question

**URL:** <https://www.ruby-forum.com/t/strange-unit-testing-error-newbie-question/54589>\
**Category:** Rails\
**Created:** [March 9, 2006, 10:41am UTC](https://www.ruby-forum.com/t/strange-unit-testing-error-newbie-question/54589 "2006-03-09T10:41:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [March 9, 2006, 10:41am UTC](https://www.ruby-forum.com/t/strange-unit-testing-error-newbie-question/54589/1 "2006-03-09T10:41:18Z")

</div>

I’m fairly new to Rails, and I’ve been learning from AGILE WEB  
DEVELOPMENT WITH RAILS. Everything has been going smoothly until the  
chapter on Unit Testing, where I’m getting some strange errors.

I’m up to page 141 in the Agile book, and attempting to run the test  
program containing the method test\_read\_with\_hash. The previous tests  
work properly, but I don’t seem to be able to refer to the fixtures  
through its variable.

The file “product\_test.rb” contains the line “fixtures :products”, which  
says it should set up the variable @fixtures through which I can refer  
to my fixtures. My “products.yml” fixture file is exactly as downloaded  
from the Agile Web Dev site, I’ve checked it for syntax and spelling and  
tabs-instead-of-spaces and the like.

“product\_test.rb”, in the method “test\_read\_with\_hash” contains this  
line:

```
vc_book = @products["version_control_book"]

```

When I run product\_test.rb, I get a NoMethodError on this line:

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/product\_test.rb:71:in `test\_read\_with\_hash’

My actual “depot” application works perfectly as far as I can tell, and  
I’d like to debug this but I’m not sure how to trace it back. What  
could cause this error, how would I go about finding it?

Thanks in advance,  
Jeff C.man

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [March 10, 2006, 3:50am UTC](https://www.ruby-forum.com/t/strange-unit-testing-error-newbie-question/54589/2 "2006-03-10T03:50:38Z")

</div>

Just checking again to see if anyone has any ideas on this. What could  
lead the unit testing processes to be unable to form an array of  
fixtures?

Jeff C.man wrote:

> I’m fairly new to Rails, and I’ve been learning from AGILE WEB  
> DEVELOPMENT WITH RAILS. Everything has been going smoothly until the  
> chapter on Unit Testing, where I’m getting some strange errors.
> 
> I’m up to page 141 in the Agile book, and attempting to run the test  
> program containing the method test\_read\_with\_hash. The previous tests  
> work properly, but I don’t seem to be able to refer to the fixtures  
> through its variable.
> 
> The file “product\_test.rb” contains the line “fixtures :products”, which  
> says it should set up the variable @fixtures through which I can refer  
> to my fixtures. My “products.yml” fixture file is exactly as downloaded  
> from the Agile Web Dev site, I’ve checked it for syntax and spelling and  
> tabs-instead-of-spaces and the like.
> 
> “product\_test.rb”, in the method “test\_read\_with\_hash” contains this  
> line:
> 
> ```
> vc_book = @products["version_control_book"]
> 
> ```
> 
> When I run product\_test.rb, I get a NoMethodError on this line:
> 
> 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/product\_test.rb:71:in `test\_read\_with\_hash’
> 
> My actual “depot” application works perfectly as far as I can tell, and  
> I’d like to debug this but I’m not sure how to trace it back. What  
> could cause this error, how would I go about finding it?
> 
> Thanks in advance,  
> Jeff C.man

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [March 10, 2006, 6:42am UTC](https://www.ruby-forum.com/t/strange-unit-testing-error-newbie-question/54589/3 "2006-03-10T06:42:50Z")

</div>

A few things have changed regarding unit testing since the first edition  
of the book. Read this… [http://clarkware.com/cgi/blosxom/2005/10/24](http://clarkware.com/cgi/blosxom/2005/10/24)

\_Kevin

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [March 10, 2006, 7:10am UTC](https://www.ruby-forum.com/t/strange-unit-testing-error-newbie-question/54589/4 "2006-03-10T07:10:00Z")

</div>

Jeff C.man wrote:

> ```
> vc_book = @products["version_control_book"]
> 
> ```
> 
> When I run product\_test.rb, I get a NoMethodError on this line:

You’re probably running rails 1.0 and the book was pre-1.0; and  
unfortunately the way that fixtures are handled changed in 1.0.

@products is not automatically created for you like the book says.  
However, an easy method is defined for you instead, called products():

vc\_book = products(:version\_control\_book)

This tripped me up when I upgraded to 1.0 back in December and  
unfortunately continues to be a problem for anyone who now buys the  
book.

Other than that, the book is awesome, and not too many other things are  
out of date. You should check the errata site for the book while you’re  
at it (I don’t have the url at hand, go to [www.pragmaticprogrammer.com](http://www.pragmaticprogrammer.com)  
and I’m sure you can find it).

Jeff

> **[Hey Daddio!](http://www.softiesonrails.com)**
>
> Home of Hey Daddio Software

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [March 10, 2006, 11:22am UTC](https://www.ruby-forum.com/t/strange-unit-testing-error-newbie-question/54589/5 "2006-03-10T11:22:00Z")

</div>

Thanks! That’s definitely something I didn’t know.

Jeff C.man
