Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinklepsch/1442300 to your computer and use it in GitHub Desktop.
Save martinklepsch/1442300 to your computer and use it in GitHub Desktop.
How to fabricate multiple objects in a spec with Fabrication

How to Fabricate Multiple Objects in a Spec with Fabrication

1. Fabricate(:a, :count => 2)

Fabricate(:a, :count => 2)
...
NoMethodError: undefined method `count=' for #<Ad:0x12e4ec8c8>

This one is kind of obvious since this is usually the syntax to override specific attributes.

2. [Fabricate(:a), Fabricate(:a)]

ree-1.8.7-2011.03 :003 > [Fabricate(:a), Fabricate(:a)]
...

3. 2.times Fabricate(:a)

This is probably the best possible solution right now.

@phoet
Copy link

phoet commented Apr 7, 2021

Fabricate.times(2, :a)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment