【发布时间】:2014-11-18 21:43:44
【问题描述】:
我正在尝试使用 FactoryGirl 创建一个项目列表,但我需要这些项目不按顺序排列。这是我所拥有的,但我希望它是 DRYer。
spec.rb
context "three out of order" do
before do
FactoryGirl.create(:thing, ordering: 3)
FactoryGirl.create(:thing, ordering: 1)
FactoryGirl.create(:thing, ordering: 2)
end
it "should sort the things in order" do
expect(Thing.all.map(&:ordering)).to eq([1, 2, 3])
end
end
我知道您可以使用以下方法创建多个项目:
FactoryGirl.create_list(:thing, ordering: 3 )
但我想创建项目,所以它测试了它们的顺序,因为我在工厂中设置了序列,所以它们会按顺序创建所有它们。
【问题讨论】:
标签: ruby-on-rails ruby rspec factory-bot