debian-mirror-gitlab/spec/support/matchers/pushed_frontend_feature_flags_matcher.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

28 lines
771 B
Ruby
Raw Normal View History

2021-03-11 19:13:27 +05:30
# frozen_string_literal: true
RSpec::Matchers.define :have_pushed_frontend_feature_flags do |expected|
def to_js(key, value)
"\"#{key}\":#{value}"
end
2022-05-07 20:08:51 +05:30
def html(actual)
actual.try(:html) || actual
end
2021-03-11 19:13:27 +05:30
match do |actual|
expected.all? do |feature_flag_name, enabled|
2022-05-07 20:08:51 +05:30
html(actual).include?(to_js(feature_flag_name, enabled))
2021-03-11 19:13:27 +05:30
end
end
failure_message do |actual|
missing = expected.select do |feature_flag_name, enabled|
2022-05-07 20:08:51 +05:30
!html(actual).include?(to_js(feature_flag_name, enabled))
2021-03-11 19:13:27 +05:30
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