1
FactoryGirl.define do
  sequence :email do |n|
    "user#{n}@example.com"
  end

  factory :user do
    email {FactoryGirl.generate :email}
    password "abc"
    admin false
  end
end

工作得很好,但如果我这样做

FactoryGirl.define do
  sequence :email {|n| "user#{n}@example.com"}

  factory :user do
    email {FactoryGirl.generate :email}
    password "abc"
    admin false
  end
end

我收到以下错误

/Users/brad/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:235:in `load': /Users/brad/Ruby_Rails/acute_pain/spec/factories.rb:2: syntax error, unexpected '{', expecting keyword_end (SyntaxError)
  sequence :email {|n| "user#{n}@example.com"}
                   ^

哇哦?

我正在使用 Factory Girl 3.1.0 和 Rails 3.0.10。

4

1 回答 1

2

注意参数!:)

sequence(:email) {|n| "user#{n}@example.com"}
于 2012-04-11T11:42:05.033 回答