Rails FactoryGirl instance variable
<p>I would like to create factory using local variable.
Currently I have the following factory:</p>

<pre><code>FactoryGirl.define do
  factory :offer_item, class: BackOffice::OfferItem do
    service
    variant
  end
end
</code></pre>

<p>My expectation is to create something like below</p>

<pre><code> FactoryGirl.define do
    variant = FactroyGirl.create(:variant)
    factory :offer_item, class: BackOffice::OfferItem do
      service
      variant { variant }

      after(:create) do |offer_item|
        offer_item.service.variants &lt;&lt; variant
      end
    end
  end
</code></pre>

<p>but then I get:</p>

<pre><code>/.rvm/gems/ruby-2.2.3/gems/factory_girl-4.7.0/lib/factory_girl/registry.rb:24:in `find': Factory not registered: variant (ArgumentError)
</code></pre>

<p>All models are nested inside <code>BackOffice</code> module. Generally I want the same object has association with two other objects. I think there is a some problem with scope in my factory.</p>

<p>Variant factory is inside other separated file.</p>