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
This commit is contained in:
Daniel Uber 2022-02-17 16:21:29 -06:00 committed by GitHub
parent 875b1a2823
commit 41ab94eaae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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