Problem with making tests flexible

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 :frowning:

Any suggestions why this hash is empty ?

Thnx a lot
LuCa

ps my fixture looke something like
first:
id: 1

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)

thnx a lot!

so the book is not perfect :slight_smile:

LuCa