English 中文(简体)
我如何界定吉拉尔工厂的顺序?
原标题:How do I define sequences in FactoryGirlRails?

Previously in Factory girl, we could define sequences like so:

# /spec/factories.rb

FactoryGirl.define do

  # this is the sequence in question:
  sequence(:random_token) { Digest::MD5.hexdigest(rand.to_s) }

  factory :story do
    sequence(:title) { |n| "My Cool Story##{n}"  }
    # Call the sequence here:
    token { Factory.next(:random_token) }
    description { "#{title} description"}
  end

end

现在,在我尝试这一办法时,我收到了一份解释性警告,告诉我:

WARNING: FactoryGirl::Sequence#next is deprecated.
Use #run instead.

When I replace #next with #run, I get a no-method error. I can t find the new syntax in any of the docs... Can anyone point me in the right direction?

增 编

最佳回答

我认为,你应当使用<代码>Factory.create(......),例如,

token { Factory.create(:random_token) }
问题回答

暂无回答




相关问题
Factory Girl and has_one

Here s my models : Class Audition belongs_to :video end Class Video has_one :audition end and my factories : Factory.define :video do |v| v.filename {Sham.filename} v.video_url {Sham.url} ...

Authlogic: logging-in twice on the same test

Is there any way to logout and login another user when testing with Authlogic? The following test case just fails class MessagesControllerTest < ActionController::TestCase setup :...

Machinist vs FactoryGirl - pros and cons

I m working with factory_girl, but looking at the machinist gem. Could you tell me please - what are the pros and cons of migrating to machinist? Have you compared those libs?

Accessing Related Model s not yet mentioned

I have a User factory that references a Company Factory.define :user do |f| f.first_name "John" f.last_name "Smith" f.password "test01" f.password_confirmation {|u| u.password} f.email "...

积极支持:试验: 单位测试铁路的情况

我最近注意到,如果我的测试分级,在我进行测试之后,我的测试数据库没有清理。 测试: 单位:试验室。 如果我的测试分级积极支持:试验,所有东西都清理了......

testing and establish_connection

How do I write tests for projects which use establish_connection in model to connect to another database?

Silencing Factory Girl logging

Just to clear the air, I am not some cruel factory master trying to silence working ladies. I am having a very annoying problem where when using Thoughtbot s factory girl in my specs, every time ...

热门标签