# Problem with making tests flexible

**URL:** <https://www.ruby-forum.com/t/problem-with-making-tests-flexible/78922>\
**Category:** Rails\
**Created:** [December 10, 2006, 4:31pm UTC](https://www.ruby-forum.com/t/problem-with-making-tests-flexible/78922 "2006-12-10T16:31:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeanluca](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@jeanluca](https://www.ruby-forum.com/u/jeanluca)\
**Post date:** [December 10, 2006, 4:31pm UTC](https://www.ruby-forum.com/t/problem-with-making-tests-flexible/78922/1 "2006-12-10T16:31:54Z")

</div>

Hi All

I’m reading stuff from ‘Agile Web development With Ruby on Rails’ (p  
141)  
Anyway, they say that there is a variable that contains all the data  
from the fixture!

Example:  
fixtures :address

def setup  
@address = Address.find(1)  
end

def test\_create  
data = @addresses[“first”] # this is line 11  
assert\_kind\_of Address, @address  
assert\_equal data[“id”], @address.id  
… etc…  
end

So assumed is that all data from the fixture is loaded into the hash  
@addresses. But Running this test I get an error on @addresses:

Loaded suite address\_test  
Started  
E…  
Finished in 0.125989 seconds.

1. Error:  
test\_create(AddressTest):  
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.[]  
address\_test.rb:11:in `test\_create’

3 tests, 4 assertions, 0 failures, 1 errors

So it seems there is no @addresses ☹

Any suggestions why this hash is empty ?

Thnx a lot  
LuCa

ps my fixture looke something like  
first:  
id: 1  
…

---

<div class="post-metadata">

**Author:** ![jeanluca](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@jeanluca](https://www.ruby-forum.com/u/jeanluca)\
**Post date:** [December 10, 2006, 4:50pm UTC](https://www.ruby-forum.com/t/problem-with-making-tests-flexible/78922/2 "2006-12-10T16:50:02Z")

</div>

Luca S. wrote:

> ```
> data = @addresses["first"] # this is line 11
> 
> ```

Fixtures create an accessor method, where you can pass in the name of  
the indivisual fixture. This is not an instance variable, but a method  
instead.

Try:

addresses(:first)

---

<div class="post-metadata">

**Author:** ![jeanluca](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@jeanluca](https://www.ruby-forum.com/u/jeanluca)\
**Post date:** [December 10, 2006, 4:57pm UTC](https://www.ruby-forum.com/t/problem-with-making-tests-flexible/78922/3 "2006-12-10T16:57:54Z")

</div>

thnx a lot!

so the book is not perfect 🙂

LuCa
