Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 如何在FactoryGirlRails中定义序列?_Ruby On Rails 3_Rspec2_Factory Bot - Fatal编程技术网

Ruby on rails 3 如何在FactoryGirlRails中定义序列?

Ruby on rails 3 如何在FactoryGirlRails中定义序列?,ruby-on-rails-3,rspec2,factory-bot,Ruby On Rails 3,Rspec2,Factory Bot,以前在Factory girl中,我们可以这样定义序列: # /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}" }

以前在Factory girl中,我们可以这样定义序列:

# /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.
当我将#next替换为#run时,我得到一个无方法错误。 我在任何文档中都找不到新语法。。。谁能给我指出正确的方向吗


谢谢

我认为你应该使用
工厂。改为创建(…)
,例如

token { Factory.create(:random_token) }

谢谢,这帮了大忙!