I have the following factory:
FactoryGirl.define do
factory :foo do
sequence(:name) { |n| "Foo #{n}" }
trait :y do
sequence(:name) { |n| "Fooy #{n}" }
end
end
end
If I run
create :foo
create :foo
create :foo, :y
I get Foo 1, Foo 2, Fooy 1
. But I want Foo1, Foo2, Fooy 3
. How can I achieve this?
After a couple of hints from smile2day's answer and this answer, I came to the following solution:
FactoryGirl.define do
sequence :base_name do |n|
" #{n}"
end
factory :foo do
name { "Foo " + generate(:base_name) }
trait :y do
name { "Fooy " + generate(:base_name) }
end
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With