forked from thoughtbot/factory_bot
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added create|build_list for easy generation of multiple factories at …
…once Closes thoughtbot#110
- Loading branch information
1 parent
2ba2dc1
commit dd7aa22
Showing
4 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require 'spec_helper' | ||
require 'acceptance/acceptance_helper' | ||
|
||
describe "build multiple instances" do | ||
before do | ||
define_model('Post', :title => :string) | ||
|
||
FactoryGirl.define do | ||
factory(:post) do |post| | ||
post.title "Through the Looking Glass" | ||
end | ||
end | ||
end | ||
|
||
context "without default attributes" do | ||
subject { FactoryGirl.build_list(:post, 20) } | ||
|
||
its(:length) { should == 20 } | ||
|
||
it "builds (but doesn't save) all the posts" do | ||
subject.each do |record| | ||
record.should be_new_record | ||
end | ||
end | ||
|
||
it "uses the default factory values" do | ||
subject.each do |record| | ||
record.title.should == "Through the Looking Glass" | ||
end | ||
end | ||
end | ||
|
||
context "with default attributes" do | ||
subject { FactoryGirl.build_list(:post, 20, :title => "The Hunting of the Snark") } | ||
|
||
it "overrides the default values" do | ||
subject.each do |record| | ||
record.title.should == "The Hunting of the Snark" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require 'spec_helper' | ||
require 'acceptance/acceptance_helper' | ||
|
||
describe "create multiple instances" do | ||
before do | ||
define_model('Post', :title => :string) | ||
|
||
FactoryGirl.define do | ||
factory(:post) do |post| | ||
post.title "Through the Looking Glass" | ||
end | ||
end | ||
end | ||
|
||
context "without default attributes" do | ||
subject { FactoryGirl.create_list(:post, 20) } | ||
|
||
its(:length) { should == 20 } | ||
|
||
it "creates all the posts" do | ||
subject.each do |record| | ||
record.should_not be_new_record | ||
end | ||
end | ||
|
||
it "uses the default factory values" do | ||
subject.each do |record| | ||
record.title.should == "Through the Looking Glass" | ||
end | ||
end | ||
end | ||
|
||
context "with default attributes" do | ||
subject { FactoryGirl.create_list(:post, 20, :title => "The Hunting of the Snark") } | ||
|
||
it "overrides the default values" do | ||
subject.each do |record| | ||
record.title.should == "The Hunting of the Snark" | ||
end | ||
end | ||
end | ||
end |