title: Rspec how to stub an object created within a method
body: <p>I am in the process of refactoring a bloated controller that serves a polymorphic model for carousels. I am trying to build a class method that handles finding and returning the item that is carouselable. </p>
  
  <p>In my RSPEC tests I want to stub the method, 'is_something?' on the venue that is found as a result of the params.</p>
  
  <pre><code>  def self.find_carouselable(params)
      .......
      elsif params[:venue_id].present?
        venue=Venue.friendly.find(params[:venue_id])
        if venue.is_something? 
          do this 
        else
          do that
        end
      end
    end
  </code></pre>
  
  <p>I cant work out how to stub an object that is created as a result of the inputted data - I am not sure if this is called stubbing or mocking? </p>
  
  <pre><code>  context "carouselable is a venue" do 
      before do 
        allow(the_venue).to receive(:is_something?).and_return(true)
      end
  
      it "returns the instance of the carouselable object" do 
        expect(CopperBoxCarouselItem.find_carouselable(venue_params)).to eq the_venue
      end
     end
  </code></pre>
  
  <p>many thanks</p>