My first test - named fixture not autoloading instance varia

I’m trying to write a test like the one at the bottom of page 148 in
Agile Rails.

I’m using rails 1.0

I’ve created the fixture correctly I’m pretty sure because the test
database table is being populated per the fixture.

I have what I think is a simple unit test:

require File.dirname(FILE) + ‘/…/test_helper’

class CaseTest < Test::Unit::TestCase
fixtures :cases

def setup
@case = Case.find(1)

Replace this with your real tests.

def test_verify_schema_has_correct_fields
assert_kind_of Case, @case
assert_equal 1,
assert_equal “F-06-101”, @case.case_number
assert_equal @first.case_number, @case.case_number

The first 2 assert_equal statements are working fine and demonstrate
the basic table logic is fine and that my fixture is working.

The third one is failing because @first is nil.

Per the book @first should be automatically created because it is the
name of my fixture. (ie. the scaffold named the first fixture “first”
and I should be able to reference it as @first.)

Any idea what is wrong?


Greg F.
The Norcross Group
Forensics for the 21st Century

If in test_helper.rb you have use_instantiated_fixtures = false, then
your fixtures will not be pre-instantiated into instance variables.
You can still access the fixture you want using cases(:first)

Tom W.

That worked. Thanks Tom

On 1/16/06, Tom W. [email protected] wrote:

I’m using rails 1.0


Rails mailing list
[email protected]

Greg F.
The Norcross Group
Forensics for the 21st Century

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs