1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00
thoughtbot--factory_bot/spec/acceptance/build_list_spec.rb

55 lines
1.3 KiB
Ruby
Raw Normal View History

describe "build multiple instances" do
before do
define_model("Post", title: :string, position: :integer)
FactoryBot.define do
factory(:post) do |post|
post.title { "Through the Looking Glass" }
post.position { rand(10**4) }
end
end
end
context "without default attributes" do
subject { FactoryBot.build_list(:post, 20) }
2013-01-18 13:27:57 -05:00
its(:length) { should eq 20 }
it "builds (but doesn't save) all the posts" do
subject.each do |record|
2013-01-18 13:27:57 -05:00
expect(record).to be_new_record
end
end
it "uses the default factory values" do
subject.each do |record|
2013-01-18 13:27:57 -05:00
expect(record.title).to eq "Through the Looking Glass"
end
end
end
context "with default attributes" do
subject { FactoryBot.build_list(:post, 20, title: "The Hunting of the Snark") }
it "overrides the default values" do
subject.each do |record|
2013-01-18 13:27:57 -05:00
expect(record.title).to eq "The Hunting of the Snark"
end
end
end
context "with a block" do
subject do
FactoryBot.build_list(:post, 20, title: "The Listing of the Block") do |post|
post.position = post.id
end
end
it "correctly uses the set value" do
2018-10-05 14:54:08 -04:00
subject.each do |record|
2013-01-18 13:27:57 -05:00
expect(record.position).to eq record.id
end
end
end
end