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

Add error message when count is missing for create_list

Closes #889

`create_list` was failing abruptly if the second argument was not
count. Give a descriptive error message for this case.
This commit is contained in:
Tejas Bubane 2016-08-26 18:10:56 +05:30 committed by Jason Draper
parent 444d00067f
commit 8a65569f10
2 changed files with 12 additions and 0 deletions

View file

@ -25,6 +25,10 @@ module FactoryGirl
strategy_name = @strategy_name
define_syntax_method("#{strategy_name}_list") do |name, amount, *traits_and_overrides, &block|
unless amount.respond_to?(:times)
raise ArgumentError, "count missing for #{strategy_name}_list"
end
amount.times.map { send(strategy_name, name, *traits_and_overrides, &block) }
end
end

View file

@ -53,6 +53,14 @@ describe "create multiple instances" do
end
end
end
context "without the count" do
subject { FactoryGirl.create_list(:post, title: "The Hunting of the Bear") }
it "raise ArgumentError with the proper error message" do
expect { subject }.to raise_error(ArgumentError, /count missing/)
end
end
end
describe "multiple creates and transient attributes to dynamically build attribute lists" do