title: Rails SystemStackError: stack level too deep
body: <p>I am testing my app ( Rails 5) with rspec capybara and factory girl I have the following error...
  I am not sure what's happening... I am very new with rspec I hope you could help me :) thank you</p>
  
  <pre><code>Randomized with seed 41137
  
  An error occurred in a `before(:suite)` hook.
  Failure/Error: FactoryGirl.lint
  
  SystemStackError:
    stack level too deep
  </code></pre>
  
  <p>You will find my code below:</p>
  
  <p>factories.rb</p>
  
  <pre><code>FactoryGirl.define do
    factory :event do
      name {Faker::Friends.character}
      total_price 50
      participant
    end
  
    factory :participant do
      first_name { Faker::Name.first_name }
      salary 900
      event
    end
  end
  </code></pre>
  
  <p>event.rb</p>
  
  <pre><code>class Event &lt; ApplicationRecord
    has_many  :participants, inverse_of: :event
    validates :participants, presence: true
    validates :name, presence: true, length: {minimum: 2}
    validates :total_price, presence: true
  
  
    accepts_nested_attributes_for :participants, reject_if: :all_blank, allow_destroy: true
  
    def total_salary
      all_salary = []
      participants.each do |participant|
        all_salary &lt;&lt; participant.salary
      end
      return @total_salary = all_salary.inject(0,:+)
    end
  end
  </code></pre>
  
  <p>event_spec.rb</p>
  
  <pre><code>require 'rails_helper'
  
  describe Event do
    it { should have_many(:participants) }
    it { should validate_presence_of(:participants) }
    it { should validate_presence_of(:name) }
    it { should validate_presence_of(:total_price) }
  
    describe "#total_salary" do
      it "should return the total salary of the participants" do
        partcipant_1 = create(:participant, salary: 2000)
        partcipant_2 = create(:participant, salary: 3000)
  
        expect(partcipant_1.salary + partcipant_2.salary).to eq(5000)
      end
    end
  end
  </code></pre>
  
  <h2>edit</h2>
  
  <p>In my participant model I had to add <code>optional: true</code>
  <code>belongs_to :event, option: true</code></p>
  
  <p>so fabriciofreitag suggestion works well :)</p>