Question: Is there any way to test custom pluralization rules using Rspec in rails

Question

Is there any way to test custom pluralization rules using Rspec in rails

Answers 0
Added at 2017-07-26 18:07
Tags
Question

I have added custom pluralization rules for Korean locale and was wondering if there was a way to test this using Rspec.To add custom rules I have added the following code at /config/initializers/pluralization.rb:

require "i18n/backend/pluralization"
I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)

and added the custom rules at config/locales/plurals.rb which as of now is

{
  :ko => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } }
}

When I try testing it using rails console, I see that the custom rules are in effect, but when I try the same translation in my spec folder while running an Rspec test I get the following error:

I18n::InvalidPluralizationData: translation data {:other=>"%{count} xxxxxxxx"} can not be used with :count => 1

My spec file looks like this: Path: /spec/locales/default_pluralization_key_ko_spec.rb

Rspec.describe "Korean Locale Pluralization Test" do

  describe "checking korean" do
    it  "korean pluralization with keys only :other" do
      I18n.locale = :ko
      I18n.t('views.project.drawing_log.upload_sub_text', count:1)

    end
  end
end
Answers to

Is there any way to test custom pluralization rules using Rspec in rails

Source Show
◀ Wstecz