title: Using described_class when including a module under test
body: <p>I am writing some rspec's to test some modules correctly implement their behaviour.</p>
  
  <p>The module looks like this:</p>
  
  <pre><code>module Under::Test
    def some_behaviour
    end
  end
  </code></pre>
  
  <p>I can't do this in RSpec:</p>
  
  <pre><code>describe Under::Test do
    subject {Class.new{include described_class}.new}
  </code></pre>
  
  <p>At the point <code>#described_class</code> is called, it can no longer be resolved because self is an instance of Class, which doesn't have a #describe_class method. So I am forced to repeat myself:</p>
  
  <pre><code>subject {Class.new{include Under::Test}.new}
  </code></pre>
  
  <p>Or use it in the spec in a different way to how it's used by my clients:</p>
  
  <pre><code>subject {Object.new.extend described_class}
  </code></pre>
  
  <p>This has the same end effect, but something in me thinks that if I'm asking my clients to <code>include Under::Test</code>, then the tests should look as close to how it's used by them as possible.</p>
  
  <p>I can use the closure property to fix this, but I wonder if it's no better. Does this have code smell?</p>
  
  <pre><code>describe Under::Test do
    subject {mudule = described_class;Class.new{include mudule}.new}
  
    it 'has some behaviour' do
      expect(subject.some_behaviour).to be
    end
  end
  </code></pre>
  
  <p>Note, I also asked in r/ruby on reddit, someone there suggested:</p>
  
  <pre><code>subject {Class.new.include(described_class).new}
  </code></pre>
  
  <p>which might be how I go.</p>