title: Repeating RSpec example groups with different arguments
body: <p>I'm trying to keep my specs clean and DRY, but I have some tests for an API that are identical except for which version of the API is being tested. I could repeat the specs simply using something like this:</p>
  
  <pre><code>%w( v1 v2 ).each do |version|
    describe "Query #{version} API" do
      it "responds with JSON"
        # make the call using the version 
      end
    end
  end
  </code></pre>
  
  <p>But I'd like something a bit cleaner, and so I've written this method:</p>
  
  <pre><code>module RepetitivelyDescribe
    def repetitively_describe(*args, &amp;example_group_block)
      options = args.extract_options!
      options.delete(:for).each do |item|
        item_args = args.collect(&amp;:dup) + [options.dup]
        item_args[0] &lt;&lt; " [#{item}]"
  
        describe(*item_args) do
          example_group_block.call item
        end
      end
    end
  end
  
  RSpec::Core::ExampleGroup.extend RepetitivelyDescribe
  </code></pre>
  
  <p>And then my test could look more like this:</p>
  
  <pre><code>repetitively_describe "Query API", :for =&gt; %( v1 v2 ) do |version|
    it "responds with JSON"
      # make the call using the version 
    end
  end
  </code></pre>
  
  <p>I realise this is a little bit of pedantry, but it's one less level of indentation, and if I'm going to be making this call a lot, I'd like to have it cleaner.</p>
  
  <p>But of course, it's not working quite as I'd like. The call to <code>describe</code> within my <code>repetitively_describe</code> doesn't get logged to the RSpec output (when using the documentation format output), though the examples within do get repeated and use the version block argument as expected. Essentially, that level of context is lost (<code>describe</code> blocks outside and inside of the <code>repetitively_describe</code> block are kept).</p>
  
  <p>There's more detailed example code in <a href="https://gist.github.com/c2001b57c258e932313a" rel="noreferrer">a gist</a> should it be needed. Any clues on why this isn't quite working right?</p>