title: How to test that a before_filter works correctly with RSpec in Rails
body: <p>I have a <code>check_user_access_control</code> before_filter in my ApplicationController that checks the logged user's roles and permissions before it lets him through. I am trying to write some tests on it and I can't find a good way of doing it.</p>
  
  <p>For simple index actions I simply do:</p>
  
  <pre><code>it "allows access to mod" do
    login_as(Factory(:mod)) # this is a spec helper
    get :index
    response.code.should == "200"
  end
  </code></pre>
  
  <p>and it works just fine. For edit/show/create and other actions that need some params, interactions with the database and possible redirect after they run, it needs too many other stuff to be stubbed.</p>
  
  <p><strong>Is there a way to test if a specific action has been called after the before_filters?</strong> I am looking for something like <code>controller.should_receive(:action_name)</code> (which doesn't work) to replace the <code>response.code.should == "200"</code> line with.</p>
  
  <p>versions: rails 3.0.4 and rspec 2.5</p>
  
  <p>I tried another approach. We have a method in ApplicationController called <code>redirect_to_login</code> that I am now checking for with <code>controller.should_receive(:redirect_to_login)</code> and works.</p>
  
  <p>While it detects correctly if the user is allowed or not, it stubs the method, which means that the controller action is run whether or not the user is allowed. Moreover the action depends on params and database and we don't want that.</p>
  
  <p>If now I stub the action method with <code>controller.stub!(:action_name)</code>, the action is not run but RSpec is still looking for the template. Well, some actions don't have templates, they just end with a <code>redirect_to :action =&gt; :somewhere_else</code> or <code>render :text =&gt; "foobar"</code> which at this point we don't care about.</p>
  
  <p>In sort, what I need now is to find a way to make RSpec <strong>NOT</strong> worry about the template's existence.</p>