From 41ab94eaaeef18154e5f33d614262e97f9d8e0a4 Mon Sep 17 00:00:00 2001 From: Daniel Uber Date: Thu, 17 Feb 2022 16:21:29 -0600 Subject: [PATCH] Show missing translation keys when test fails (#16637) * report key and path for missing keys * move iteration out of the string into the method * make the details common to the missing and unused lists --- spec/i18n_spec.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/spec/i18n_spec.rb b/spec/i18n_spec.rb index eb781fc22..b74b316d9 100644 --- a/spec/i18n_spec.rb +++ b/spec/i18n_spec.rb @@ -6,14 +6,20 @@ RSpec.describe I18n do let(:unused_keys) { i18n.unused_keys } let(:inconsistent_interpolations) { i18n.inconsistent_interpolations } + def details(keys) + keys.leaves.map do |node| + { key: node.full_key, file: node.data[:path] } + end + end + it "does not have missing keys" do expect(missing_keys).to be_empty, - "Missing #{missing_keys.leaves.count} i18n keys, run `i18n-tasks missing' to show them" + "Missing #{missing_keys.leaves.count} i18n keys\n #{details(missing_keys)}" end xit "does not have unused keys" do expect(unused_keys).to be_empty, - "#{unused_keys.leaves.count} unused i18n keys, run `i18n-tasks unused' to show them" + "#{unused_keys.leaves.count} unused i18n keys\n #{details(unused_keys)}" end # NOTE: [@rhymes] disabling normalization check for now as it fails on CI but