title: How do I stub ::Rails.root in rspec?
body: <p>I'm writing a gem that can be used both with and without rails. In a few places I use code like</p>
  
  <pre><code>path = Rails.root if defined?(::Rails)
  </code></pre>
  
  <p>and I want to test this logic with rspec. I have tried stubbing it like</p>
  
  <pre><code>stub(:"::Rails").should_receive(:root).and_return("/rails")
  </code></pre>
  
  <p>but this does not make <code>defined?(::Rails)</code> evaluate to <code>true</code>.</p>