title: How to stub a method in cucumber?
body: <p>I want to stub out the space_available_mb method in SubmissionsController so that it returns 5. This doesn't work. It returns the correct space on the real hard disk. </p>
  
  <p>if <code>space_available_mb</code> is commented out, an expectation error is thrown, which means <code>should_receive</code> works correctly. However, it doesn't return 5, but the real number, which means <code>and_return</code> fails for some reason.</p>
  
  <p>Further debugging reveals that <code>and_return</code> is actually called, but only after the method has run and returned the real number.</p>
  
  <pre><code>Scenario: Hard Disk Space is low on new submission
    Given I am on the new_submission page
    And hard disk space is low
    Then I should see "Low disk space!"
  
  Given /^hard disk space is low$/ do
    SubmissionsController.should_receive(:space_available_mb).and_return(5)
  end
  
  class SubmissionsController &lt; ApplicationController
    include FileManager
  
    def new
      space = space_available_mb
      ...
    end
  end
  
  module FileManager
    def space_available_mb
      ...
    end
  end
  </code></pre>