title: Mocking `Rails.logger` in the RSpec tests for my Gem
body: <p>I'm writing a Ruby gem, and below is the implementation of how I create a new <code>Logger</code>.</p>
  <p>My gem may or may not be used inside of Rails, so it tries to use <code>Rails.logger</code> IF one exists.</p>
  <pre><code>require 'logger'
  
  module MyLoggeer
    def logger
      @logger ||= rails_logger || Logger.new($stdout)
    end
  
    def rails_logger
      if defined?(::Rails) &amp;&amp; ::Rails.respond_to?(:logger) &amp;&amp; !::Rails.logger.nil?
        ::Rails.logger
      else
        nil
      end
    end
  end
  </code></pre>
  <p>My gem does not have <code>Rails</code> defined anywhere as a constant. If I wanted to test the above logic with RSpec, is there a way for me to -</p>
  <ol>
  <li>Define a mock <code>Rails</code> object</li>
  <li>Have it respond to a <code>logger</code> method?</li>
  </ol>
  <p>I suppose I could define a dummy class inside my spec files, but I was hoping there was a way to easily mock / stub this out instead.</p>
  <p>Thanks!</p>