title: Rspec - stub module method
body: <p>How can I stub a method within a module:</p>
  
  <pre><code>module SomeModule
      def method_one
          # do stuff
          something = method_two(some_arg)
          # so more stuff
      end
  
      def method_two(arg)
          # do stuff
      end
  end
  </code></pre>
  
  <p>I can test <code>method_two</code> in isolation fine.</p>
  
  <p>I would like to test <code>method_one</code> in isolation too by stubbing the return value of <code>method_two</code>:</p>
  
  <pre><code>shared_examples_for SomeModule do
      it 'does something exciting' do
          # neither of the below work
          # SomeModule.should_receive(:method_two).and_return('MANUAL')
          # SomeModule.stub(:method_two).and_return('MANUAL')
  
          # expect(described_class.new.method_one).to eq(some_value)
      end
  end
  
  describe SomeController do
      include_examples SomeModule
  end
  </code></pre>
  
  <p>The specs in <code>SomeModule</code> that are included in <code>SomeController</code> fail because <code>method_two</code> throws an exception (it tries to do a db lookup that has not been seeded).</p>
  
  <p>How can I stub <code>method_two</code> when it is called within <code>method_one</code>?</p>