From b84bc2de5df8ea0d3e67c574ca9142efed39715e Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Mon, 15 May 2023 11:25:04 -0400 Subject: [PATCH] Replace i18n view spec with helper spec (#24966) --- spec/locales/i18n_spec.rb | 35 ++++++++++++++++++ .../shared/_error_messages.html.haml_spec.rb | 37 ------------------- 2 files changed, 35 insertions(+), 37 deletions(-) create mode 100644 spec/locales/i18n_spec.rb delete mode 100644 spec/views/shared/_error_messages.html.haml_spec.rb diff --git a/spec/locales/i18n_spec.rb b/spec/locales/i18n_spec.rb new file mode 100644 index 000000000..cfce8e223 --- /dev/null +++ b/spec/locales/i18n_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'I18n' do + describe 'Pluralizing locale translations' do + subject { I18n.t('generic.validation_errors', count: 1) } + + context 'with the `en` locale which has `one` and `other` plural values' do + around do |example| + I18n.with_locale(:en) do + example.run + end + end + + it 'translates to `en` correctly and without error' do + expect { subject }.to_not raise_error + expect(subject).to match(/the error below/) + end + end + + context 'with the `my` locale which has only `other` plural value' do + around do |example| + I18n.with_locale(:my) do + example.run + end + end + + it 'translates to `my` correctly and without error' do + expect { subject }.to_not raise_error + expect(subject).to match(/1/) + end + end + end +end diff --git a/spec/views/shared/_error_messages.html.haml_spec.rb b/spec/views/shared/_error_messages.html.haml_spec.rb deleted file mode 100644 index e7631345f..000000000 --- a/spec/views/shared/_error_messages.html.haml_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -describe 'shared/_error_messages.html.haml' do - let(:status) { Status.new } - - before { status.errors.add :base, :invalid } - - context 'with a locale that has `one` and `other` plural values' do - around do |example| - I18n.with_locale(:en) do - example.run - end - end - - it 'renders the view with one error' do - render partial: 'shared/error_messages', locals: { object: status } - - expect(rendered).to match(/is invalid/) - end - end - - context 'with a locale that has only `other` plural value' do - around do |example| - I18n.with_locale(:my) do - example.run - end - end - - it 'renders the view with one error' do - render partial: 'shared/error_messages', locals: { object: status } - - expect(rendered).to match(/is invalid/) - end - end -end