title: How to add scope-like method in a controller spec
body: <p>Another variation of this question: <strong>How to test controller scopes in DRY style?</strong></p>
  
  <p>I have a lot of scopes in controller:</p>
  
  <pre><code>class SettingsController &lt; ApplicationController
    before_filter :authenticate, :require_admin
    before_filter :navigation, only: [:show, :edit]
  
    def show
      flash[:notice] = I18n.t(:thank_you_for_your_subscription) if params[:p]
    end
  
    def edit
      render_not_found and return unless %w(username password).include?(params[:section])
  
      @section = params[:section]
    end
  ...
  </code></pre>
  
  <p>So, I have a lot of similar methods in controller specs (for actions). The typical controller spec is:</p>
  
  <pre><code>describe SettingsController do
    let!(:user) { Factory(:user) }
  
    describe "GET #show" do
      def do_action
        get :show
      end
  
      it_requires_sign_in
      it_requires_admin
      it_specifies_navigation_with 'settings'
  
      it "should set a flash message when the 'p' param is set" do
        sign_in_as user
        do_action
        flash[:notice].should_not be_nil
      end
    end
  
    describe "GET #edit" do
      def do_action options = {}
        get :edit, options.merge(format: 'rjs')
      end
  
      it_requires_sign_in
      it_requires_admin
      it_specifies_navigation_with 'settings'
  
      context "when singed in" do
        before { sign_in_as user }
  
        it "should render 404 if no section is provided" do
          do_action
          response.code.should == '404'
        end
      end
    end
  end
  </code></pre>
  
  <p>But <code>it_requires_sign_in</code> method has next representation:</p>
  
  <pre><code>def it_requires_sign_in
    it "should require sign in" do
      send do_action
      response.should redirect_to(sign_in_path)
    end
  end
  </code></pre>
  
  <p>Navigation:</p>
  
  <pre><code>def it_specifies_navigation_with(name)
    it "specifies navigation with '#{name}'" do
      controller.should receive(:current_navigation).with(name)
      sign_in_as user
      do_action
    end
  end
  </code></pre>
  
  <p>So, it uses method from describe part. Is it possible to make some kind of scope in which i could specify methods (actions), that i want to check or not, like:</p>
  
  <pre><code>describe SettingsController do
    requires_sign_in # every action (inner describe parts)
    requires_admin
    specifies_navigation_with only: [:show, :edit]
  
    let!(:user) { Factory(:user) }
  
    describe "GET #show" do
      def do_action
        get :show
      end
  
      it "should set a flash message when the 'p' param is set" do
        sign_in_as user
        do_action
        flash[:notice].should_not be_nil
      end
    end
  ...
  </code></pre>
  
  <p>The main problem is to call the exact method <code>do_action</code> in precise scope (i mean describe action part).</p>