You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: access_matchers_for_controller.rb
    path of file: ./repos/gitlabhq/spec/support/matchers
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

# AccessMatchersForController
#
# For testing authorize_xxx in controller.
module AccessMatchersForController
  extend RSpec::Matchers::DSL
  include Warden::Test::Helpers

  EXPECTED_STATUS_CODE_ALLOWED = [200, 201, 204, 302].freeze
  EXPECTED_STATUS_CODE_DENIED = [40
    
  def emulate_user(role, membership = nil)
    case role
    when :admin
      user = create(:admin)
      sign_in(user)
    when :user
      user = create(:user)
      sign_in(user)
    when :external
      user = create(:user, external: true)
      sign_in(user)
    when :visitor
      user = nil
    when User
      user = role
      sign_in(user)
    when *Gitlab::Access.sym_options_with_owner.keys # owner, maintainer, developer, reporter, guest
      raise ArgumentError, "cannot emulate #{role} without membership parent" unless membership

      user = create_user_by_membership(role, membership)
      sign_in(user)
    else
      raise ArgumentError, "cannot emulate user #{role}"
    end