Welcome to mirror list, hosted at ThFree Co, Russian Federation.

request_urgency_matcher.rb « matchers « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d3c5093719eb78f6d21f8e2bb7d1afb181b3fe14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

require 'spec_helper'

module RequestUrgencyMatcher
  RSpec::Matchers.define :have_request_urgency do |request_urgency|
    match do |_actual|
      if controller_instance = request.env["action_controller.instance"]
        controller_instance.urgency.name == request_urgency
      elsif endpoint = request.env['api.endpoint']
        urgency = endpoint.options[:for].try(:urgency_for_app, endpoint)
        urgency.name == request_urgency
      else
        raise 'neither a controller nor a request spec'
      end
    end

    failure_message do |_actual|
      if controller_instance = request.env["action_controller.instance"]
        "request urgency #{controller_instance.urgency.name} is set, \
          but expected to be #{request_urgency}".squish
      elsif endpoint = request.env['api.endpoint']
        urgency = endpoint.options[:for].try(:urgency_for_app, endpoint)
        "request urgency #{urgency.name} is set, \
          but expected to be #{request_urgency}".squish
      end
    end
  end
end