Ruby on Rails best practices in testing (flash msgs and views) and I18N
When testing Flash messages and generated views, should you test for the the generated output in one language:
should_set_the_flash_to /Hello/i
or should you bring I18N into your tests:
should_set_the_flash_to I18n.t("sign_up.welcome")
It could be that my question is just not the right question to ask... feel free to answer with a link if there are already good explanations on combining testing and i18n...
Update: put in the right internationa开发者_开发问答lisation code after Arsen7's answer, thx Arsen7!
It depends on what are you trying to test.
If you test whether the flash text is "Hello", then you are sure that you know what your user will see.
On the other hand, testing whether the flash contains the same thing as what helper "t" returns for given string, also makes sense sometimes - for example when your translation file changes often, or if its content is created by someone else, some time later.
I, personally, always test the exact, final translation (assert_equal "Hello", flash[:message]
kind of things).
It assures me that: 1) the translation sounds OK, 2) the language is correctly recognized (you don't want Polish messages for your English users, do you?)
As for the second part of your question:
Maybe "should_set_the_flash_to I18n.t("sign_up.welcome")
" will work?
精彩评论