title: RSpec - how to stub controller method
body: <p>I have a controller which has some special authentication as it is really an API available to a specific remote system.</p>
  
  <p>In RSpec (2.7), I want to bypass that authentication, but I can't seem to get it working.  From what I read, I should be doing something like this:</p>
  
  <pre><code>controller.stub!(:restrict_soa_access).and_return(true)
  </code></pre>
  
  <p>But if I do that, I just get:</p>
  
  <pre><code>spec/controllers/soa/user_controller_spec.rb:42: undefined method `stub!'
  for #&lt;RSpec::Core::Hooks::AfterHooks:0xb673a8dc&gt; (NoMethodError)
  </code></pre>
  
  <p>In response to the comments, I have also tried using <code>Soa::UserController.stub!</code> which gives an identical error, and also <code>@controller.stub!</code>, when I get undefined method for nil:NilClass.</p>
  
  <p>I'm not stubbing any other stuff.  Is there something I need to do to enable stubbing or is my stub code just wrong?</p>