title: DRY controller specs with RSpec
body: <p>I'm currently struggling a bit trying to keep my controller specs DRY and succinct and down to one assertion per example. I'm running into some difficulties particularly with where to place the actual controller request call within a structure nested to match the various edge cases.</p>
  
  <p>Here's an example, simplified to demonstrate the problem:</p>
  
  <pre><code>describe MyController do
    let(:item) { Factory(:item) }
    subject { response }
  
    describe "GET #show" do
      before(:each) do
        get :show
      end
  
      context "published item" do
        it { should redirect_to(success_url) }
      end
  
      context "unpublished item" do
        before(:each) do
          item.update_attribute(published: false)
        end
  
        it { should redirect_to(error_url) }
      end
    end
  end
  </code></pre>
  
  <p>Clearly this is a contrived example, but it illustrates what I'd like to do and what's not working. Mainly, the <code>before</code> block under the "unpublished" context is the problem. What happens is the change I made to the setup data actually happens <em>after</em> the <code>get</code> call due to the way the contexts are nested, so the example in that context is actually working with the initial scenario rather than the one I intend.</p>
  
  <p>I understand why this happens and how contexts nest. I guess what I'd <em>like</em> to have is some way to tell RSpec what I'd like it to run right <em>after</em> any <code>before</code> hooks yet right <em>before</em> any assertions within a given context. This would be perfect for controller specs. I'd like to take advantage of nesting in my controller specs to gradually build up variations of edge cases without having to scatter the <code>get</code> call or even a call to a <code>do_get</code> helper into each of my <code>it</code> assertions. This would especially get annoying to keep in sync with any custom <code>it_should</code> macros I'm using.</p>
  
  <p>Is there anything in RSpec currently to accomplish this? Are there any tricks I can use to get close? It would seem perfectly suited to the way I've seen a lot of people writing their controller specs; from what I've found, people have basically settled for having <code>do_get</code> helpers called before every assertion. Is there a better way?</p>