Modelテストのしかた

このへんを参考に、RoRで自動テストのやり方をしらべている。

上記サイトの一番最後の段落で、「Fixtures名_カラム名」と指定するとfixturesファイルから値を取ってきてくれるようなことが書いてあるんだが、これがなんかそういうふうに動かない。
その変数はnilだぞフォルゥアと言われる。おかしいなあ。


# fixtures/cities.yml
first:
id: 1
name: paris
another:
id: 2
name: dublin


# city_test.rb(抜粋)
def test_create
# Pattern1
assert_kind_of City, @city1
assert_equal @first_id, @city1.id
assert_equal @first_name, @city1.name

# Pattern2
assert_kind_of City, @city2
another = @cities[:another]
assert_equal @another["id"], @city2.id
assert_equal @another["name"], @city2.name
end


# 実行結果
Loaded suite test/unit/city_test
Started
F
Finished in 0.219 seconds.

1) Failure:
test_create(CityTest) [test/unit/city_test.rb:14]:
expected but was<1>.

1 tests, 2 assertions, 1 failures, 0 errors