Skip to content

Commit

Permalink
Add error message when count is missing for create_list
Browse files Browse the repository at this point in the history
Closes #889

`create_list` was failing abruptly if the second argument was not
count. Give a descriptive error message for this case.
  • Loading branch information
tejasbubane authored and drapergeek committed Aug 26, 2016
1 parent 444d000 commit 8a65569
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/factory_girl/strategy_syntax_method_registrar.rb
Expand Up @@ -25,6 +25,10 @@ def define_list_strategy_method
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
Expand Down
8 changes: 8 additions & 0 deletions spec/acceptance/create_list_spec.rb
Expand Up @@ -53,6 +53,14 @@
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
Expand Down

0 comments on commit 8a65569

Please sign in to comment.