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.
if space_available_mb
is commented out, an expectation error is thrown, which means should_receive
works correctly. However, it doesn't return 5, but the real number, which means and_return
fails for some reason.
Further debugging reveals that and_return
is actually called, but only after the method has run and returned the real number.
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 < ApplicationController
include FileManager
def new
space = space_available_mb
...
end
end
module FileManager
def space_available_mb
...
end
end