Ruby on Rails optimization for testing (flash messages and views) and I18N

When testing flash messages and generated views, you should test the generated output in one language:

should_set_the_flash_to /Hello/i 

or you should bring I18N to your tests:

 should_set_the_flash_to I18n.t("sign_up.welcome") 

Maybe my question is simply not the right question to ask ... feel free to respond with a link if there are already good explanations for combining testing and i18n ...

Update : enter the correct internationalization code after Arsen7 answer, thanks Arsen7!

+4
source share
1 answer

It depends on what you are trying to verify.

If you check if the flash text is β€œHello”, you are sure that you know what your user will see.

On the other hand, checking whether the flash memory contains the same as the auxiliary "t" for a given line also makes sense sometimes - for example, when your translation file is changed frequently or its contents are created by someone else, after some time.

I personally verify the exact final translation ( assert_equal "Hello", flash[:message] ).

This assures me that: 1) the translation sounds normal, 2) the language is correctly recognized (you do not want the Polish messages to be for your English users?)

Regarding the second part of your question:

Maybe " should_set_the_flash_to I18n.t("sign_up.welcome") will work?

+5
source

All Articles