title: What is the correct way to define an alias to `after` in rspec?
body: <p>Normally the <code>before</code> and <code>after</code> hooks are assumed to be "initializing" and "cleanup" code respectively. They are supposed to happen "outside of the tests themselves".</p>
  
  <p>I find myself in a situation in which I want to use <code>after</code> as the last step of all the tests in a context. But since <code>after</code> is usually meant to be "cleanup", I am afraid that my tests won't be very explicit. Here's a sample:</p>
  
  <pre><code>describe "when removing" do
    let!(:request) do
      stub_request(:delete, "http://localhost:4567/containers/#{container.id}").
      to_return(status: 200)
    end
  
    # returns an http response
    subject { client.remove(container.id) }
  
    it { should be }
    it { should include('id' =&gt; container.id) }
  
    after { expect(request).to have_been_made }
  end
  </code></pre>
  
  <p>I would like to rename that last <code>after</code> to something more explicit, like <code>invariant</code>, to indicate that it is part of the test. I have tried doing this on my spec helper:</p>
  
  <pre><code># spec_helper.rb
  
  Rspec.configure do |c|
  ...
  end
  
  RSpec::Core::Hooks.class_eval do
   alias_method :invariant, :after
  end
  </code></pre>
  
  <p>requiring <code>spec_helper</code> does not seem to throw any errors, but when I run the tests replacing <code>after</code> with <code>invariant</code> I get <code>"undefined method 'invariant' for #&lt;Class:0x007f9872b46588&gt; (NoMethodError)"</code> when running the tests.</p>