rspec testing views with internationalization?
I want to make sure I have the right meta desc/keyword and title text in my view so I want to create rspec views tests for that. Now the real challange here is how to make it work across multiple languages.
The way I've done it is:
it "should have the right page title" do
title = "some nice title here"
response.should have_tag("title", title)
end
So because the "requirement" is hard coded in that example, I am having a hard time figuring out how to do 开发者_如何学编程the same thing for all the other languages in my config/locale/.
I'm not sure if this is the best way to do it or should I just fetch the text from the locale/lang.yml like so :
it "should have the right page title" do
title = t('site.title')
response.should have_tag("title", title)
end
Thanks
This seems perfectly acceptable. I see no reason to fetch directly from the localization files.
It should give you a good indication that you are indeed using the localized calls throughout your application. You could probably even run your tests under the different locales and that would help you ensure you have all the keys filled out for each one.
It doesn't strike me as any different than testing using fixtures, it still requires that your .yml file be correct, and won't check to make sure you've created them correctly, but it does help you check that you've properly used them in your code.
精彩评论