My first test - named fixture not autoloading instance varia


#1

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)
end

Replace this with your real tests.

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

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

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


#2

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.


#3

That worked. Thanks Tom

On 1/16/06, Tom W. removed_email_address@domain.invalid wrote:

I’m using rails 1.0

end

http://lists.rubyonrails.org/mailman/listinfo/rails


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


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