I’ve implemented internationalization support for a Rails application using the I18n module, and I am now testing this implementation.
I’m using functional tests with assert_select to assert that there are no span HTML elements with the class name “translation_missing”, which works fine.
I’ve also written a helper method to get all the locale files from the config/locales directory, which works fine as well.
My problem is when I try to loop through each locale and check that there are no missing translations. If the test fails for one locale, it exits the block, reporting the failure, whereas I would like the test to continue running and output multiple failure messages where applicable. Here is the test:
test "index page no missing translations" do
# Login as admin to avoid 302 errors
login_as(@user)
# Get a list of the locales
locales = get_locales()
# Check each locale for missing translations
locales.each do |locale|
get :index, :locale => locale
assert_select "span.translation_missing", false, "Broadcasts index page: Translations missing from #{locale}.yml"
end
end
Is there any way that I can stop the block from being exited?
Thanks in advance.
You should probably metaprogram it away, e.g. something like (untested)
This will result in creating multiple tests, each of which only tests one locale, and none is messing up with the results of the others.