title: How to test service object
body: <p>I have written the service object below.</p>
  
  <pre><code>class LeadGeneration
    def initialize contact_id
      @lead = Lead.find_or_initialize_by(contact_id: contact_id)
    end
  
    def lead
      @lead
    end
  
    def activate_lead
      lead.active!
    end
  
    def stale_lead
       lead.stale!
    end
  end
  </code></pre>
  
  <p>I am a little confused on how exactly to test it. I have written the spec below</p>
  
  <pre><code>require 'spec_helper'
  
  describe LeadGeneration do
      let(:contact) { FactoryGirl.create(:contact) }
  
   it "#activate_lead" do
      lg = LeadGeneration.new(contact.id)
      expect(lg.lead).to receive(:active!)
      lg.activate_lead
    end
  
    it "#stale_lead" do
      lg = LeadGeneration.new(contact.id)
      expect(lg.lead).to receive(:stale!)
      lg.stale_lead
    end
  end
  </code></pre>
  
  <p>This spec works fine, but I would like to do it without exposing the lead that is generated. How exactly do I go about this. I could use </p>
  
  <pre><code>expect(Lead.any_instance).to receive(:active!)
  </code></pre>
  
  <p>But from my reading this is bad practice. Any thoughts?</p>