diff options
Diffstat (limited to 'spec/support/stub_languages_translation_percentage.rb')
-rw-r--r-- | spec/support/stub_languages_translation_percentage.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/spec/support/stub_languages_translation_percentage.rb b/spec/support/stub_languages_translation_percentage.rb new file mode 100644 index 00000000000..a93316288b9 --- /dev/null +++ b/spec/support/stub_languages_translation_percentage.rb @@ -0,0 +1,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 |