0

我有这个工厂:

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”吗?

4

1 回答 1

3

正确的语法是:

FactoryGirl.define do
  factory :from_sector, class: Sector do
    sequence(:name) { |n| "gti#{n}" }                                                                                                                                   
  end
end

在中线调用名称方法会使 FactoryGirl 窒息,因此输出看起来很有趣。

于 2012-06-15T17:39:41.037 回答