summaryrefslogtreecommitdiff
path: root/spec/support/stub_languages_translation_percentage.rb
blob: a93316288b914550c266d60e070366ed7df193ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# frozen_string_literal: true

module StubLanguagesTranslationPercentage
  # Stubs the translation percentage of the i18n languages
  #  - When a `blank?` list is given no stubbing is done;
  #  - When the list is not empty, the languages in the list
  #    are stubbed with the given values, any other language
  #    will have the translation percent set to 0;
  def stub_languages_translation_percentage(list = {})
    return if list.blank?

    expect(Gitlab::I18n)
      .to receive(:percentage_translated_for)
      .at_least(:once)
      .and_wrap_original do |_original, code|
        list.with_indifferent_access[code].to_i
      end
  end
end