title: Stubbing a method correctly in rspec
body: <p>I'm having trouble trying to stub a method. I have the following job:</p>
  <p>AnimalRelationJob</p>
  <pre><code>def perform(user_id, animal_id)
    user = User.find(User_id)
    animal_data = Animal::Zoo.internal_data(animal_id)
    owner_score = OwnerService.new.generate_score!(animal_data, user)
  
    AnimalMailer.animal_tips_message(user, owner_score).deliver_later
  end
  </code></pre>
  <p>I want to stub both the <code>internal_data</code> method and <code>OwnerService.generate_score</code> and test that the job was able to call AnimalMailer.animal_tips_message with the correct parameters</p>
  <pre><code>let(:m) { AnimalRelationJob.new.perform(user_id, animal_id) }
  
  before { 
    allow(OwnerAuth::Validation).to receive(:create_key) { true }
    allow_any_instance_of(OwnerService.new).to receive(:generate_score).and_return(100)
    allow(Animal::Zoo).to receive(:internal_data).and_return(1)
  
  }
  
  it &quot;should call the mailer&quot; do
    expect(m).to receive(animal_tips_message).with(admin_user, 100)
  end
  </code></pre>
  <p>I'm now getting the error:</p>
  <pre><code>undefined method `ancestors' for #&lt;OwnerService:0x0029812&gt;
  </code></pre>
  <p>I think it might be coming from me stubbing a method from the OwnerService initialize</p>
  <pre><code>class OwnerService
  
    def initialize
      validated = OwnerAuth::Validation.create_key(....)
    end
  </code></pre>