B Seven
B Seven

Reputation: 45941

How to create a sequence without a model with FactoryGirl?

I want to create a sequence without creating a model Foo:

let( :foo_id ){ sequence...? }

The following code works, but creates a model Foo.

Factory:

FactoryGirl.define do
  sequence :id do |i| 
    i 
  end

  factory :foo do
    id
    text { 'Text'}
  end
end

In spec:

let( :foo ){ create :foo )
...
# Using foo.id

How to create a numeric sequence without a model?

Upvotes: 0

Views: 65

Answers (1)

rdvdijk
rdvdijk

Reputation: 4398

FactoryGirl does not support this, but Fabrication does.

Take a look at this documentation.

Fabricate.sequence
# => 0
# => 1
# => 2

If you place such a statement in your let, you will get a new number every time:

let( :foo ){ Fabricate.sequence(:my_id) )

Upvotes: 2

Related Questions