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

pushed_frontend_feature_flags_matcher.rb « matchers « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ecd174edec9bea80709fe3c260c754241a76df9b (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
# frozen_string_literal: true

RSpec::Matchers.define :have_pushed_frontend_feature_flags do |expected|
  def to_js(key, value)
    "\"#{key}\":#{value}"
  end

  def html(actual)
    actual.try(:html) || actual
  end

  match do |actual|
    expected.all? do |feature_flag_name, enabled|
      html(actual).include?(to_js(feature_flag_name, enabled))
    end
  end

  failure_message do |actual|
    missing = expected.select do |feature_flag_name, enabled|
      !html(actual).include?(to_js(feature_flag_name, enabled))
    end

    formatted_missing_flags = missing.map { |feature_flag_name, enabled| to_js(feature_flag_name, enabled) }.join("\n")

    "The following feature flag(s) cannot be found in the frontend HTML source: #{formatted_missing_flags}"
  end
end