Topic: Unit Test does not Generate Instance Variables from YML
I am coding my first unit tests. I expected instance variables to be created for each instance named record in my test fixture, but it doesn't seem to be happening. (I'm running Ruby 1.8.2, RoR 1.1.6 should that be relevant.
This is what's in publications.yml:
pub_single_ed:
id: 1
name: Single-Editionpub_multi_ed:
id: 2
name: Multi-Edition
And this is one of my unit tests:
require File.dirname(__FILE__) + '/../test_helper'class PublicationTest < Test::Unit::TestCase
fixtures :publicationsdef setup
@pub = Publication.find(1)
end# Replace this with your real tests.
def test_create
assert_kind_of Publication, @pub
assert_equal publications("pub_single_ed").name, @pub.name
assert_equal @pub_single_ed.name, @pub.name # <<<< This line causes an error
end
end
What I thought would happen is that I could either use the syntax publications("pub_single_ed").name or @pub_single_ed.name to refer to the values in the fixture definition. The line with the instance variable syntax generates an error.
NoMethodError: You have a nil object when you didn't expect it!
The error occured while evaluating nil.name
test/unit/publication_test.rb:14:in `test_create'
Was this feature eliminated in some version somewhere along the way, or do I need to do something special to enable it. Thanks.