title: RSpec before confusion with devise mappings
body: <p>so I need to set a devise mapping for my tests to work properly. Per <a href="https://github.com/plataformatec/devise/wiki/How-To:-Test-controllers-with-Rails-3-and-4-%28and-RSpec%29" rel="nofollow noreferrer">https://github.com/plataformatec/devise/wiki/How-To:-Test-controllers-with-Rails-3-and-4-%28and-RSpec%29</a>, I added</p>
  <pre><code>describe Api::SessionsController do
    before(:each) do
      @request.env[&quot;devise.mapping&quot;] = Devise.mappings[:admin]
    end
    ...
  end
  </code></pre>
  <p>This works fine. However, since I'll be reusing this across multiple specs, I wanted to put it in a module in a support folder. Hence:</p>
  <h1>support/devise_helper.rb</h1>
  <pre><code>module Controllers
    module DeviseHelpers
      def set_devise_mapping
        before(:each) do
          @request.env[&quot;devise.mapping&quot;] = Devise.mappings[:api_user]
        end
      end
    end
  end
  </code></pre>
  <p>And I include the module via:</p>
  <pre><code>RSpec.configure do |config|
    config.include Controllers::DeviseHelpers, type: :controller
  end
  </code></pre>
  <p>And then in the spec:</p>
  <pre><code>describe Api::SessionsController do
    set_devise_mapping
  end
  </code></pre>
  <p>and I get the following error:</p>
  <pre><code>ruby/gems/2.2.0/gems/rspec-core-3.2.0/lib/rspec/core/example_group.rb:626:in `method_missing':
   `set_devise_mapping` is not available on an example group (e.g. a `describe` or `context` block).
   It is only available from within individual examples (e.g. `it` blocks) or from constructs that run in the scope of an example (e.g. `before`, `let`, etc). (RSpec::Core::ExampleGroup::WrongScopeError)
  </code></pre>
  <p>Why do I get this? This is what the github example linked above does. Also it works without the method. I tried using :context and putting it in different places but I get an error no matter where I put it.</p>
  <p>Thanks!</p>