我有这个工厂:
FactoryGirl.define do
factory :from_sector, class: Sector do
sequence(:name) { |n| name "gti#{n}" }
end
end
但是当我这样做时:
from = FactoryGirl.create(:from_sector)
from.name #=> <Sector id: 9, name: #<FactoryGirl::Declaration::Static:0x00000002d13650 @name=:name, @ignored=false, @value="gti1">, created_at: "2012-06-15 17:24:05", updated_at: "2012-06-15 17:24:05">
“from.name”不应该返回“gti1”吗?
答案 0 :(得分:3)
正确的语法是:
FactoryGirl.define do
factory :from_sector, class: Sector do
sequence(:name) { |n| "gti#{n}" }
end
end
在线上调用名称方法扼杀了FactoryGirl,因此看起来很有趣。