-
-
Notifications
You must be signed in to change notification settings - Fork 411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rspec Issue: Missing locales in one spec breaks another #173
Comments
I believe I've encountered a similar situation where the load_path has to be defined before any It seems likely that even though the load_path is set, the actual translation data itself isn't reloaded every time a In the mean time, making test1.rb look like this should work no matter what order the specs are run in :
|
@tigrish - Your suggestion helped me work around the problem, so thank you. (Though actually I stubbed out I18n.t() rather than loading the fake locale files in every single spec). Still, seems like a bug to me. As you say, changing the load_path ought to reload the translations. |
I just had a quick look at the code in lib/i18n/config.rb and it seems to me that reloading the backend every time the load_path changes is tricky.The user of the library would need to assign to load_path an object that is a (new) subtype of Array, with a callback to reload the backend when the size or contents of the load_path change. I wonder if there is a simpler way as that feels a bit too much. |
@knservis - Well, I was presuming that the intent was that load_path could be called at any time. I got this idea from the documentation:
If that's wrong, and you're not supposed to be able to alter it after you've begun calling t(), the solution could be as simple as making that an explicit (and documented) behavior rather than a head-scratcher. For instance:
|
@lynnfaraday - If I understand the documentation you sent correctly, it says that the paths will not be loaded until they are needed so that you can swap the backend, not that they will be reloaded when updated. If it is necessary to update the paths after using them you could always reload them yourself, e.g.:
I don't think that it is particularly difficult to make the backend reload itself when the paths are updated but it might imply changes to the way people use the this library and might add complexity and reduce readability for something that may be a rare use case. What do you think? |
Hi there, It's been a while, but I don't suppose anyone has an app which reproduces this issue? That'd help tremendously in debugging this. Thanks! |
Thanks @lynnfaraday! I've been able to investigate this today and I've discovered a solution. However, it doesn't work with |
☝️ there's a PR which will fix your issue. Here's an updated Gist of the code I used to verify this patch: https://gist.github.com/radar/c74cadff6dee7988f764536d667f44df |
Just merged #348 which fixes this. Thanks @lynnfaraday! |
I'm having a weird error with the rspec tests in my app related to the I18n library. This is a Ruby app, but not Rails. I18n is version 0.6.1
If one of my tests calls I18n.t without first setting the load_path, it appears to somehow mess up subsequent tests that do actually set the load path. To illustrate this failure in a very simple manner, I created two specs that don't even use any application code:
If I adjust the file names so that the "English" translation test runs first, everything's fine:
If I adjust the file names such that the "fail" translation test runs first, it causes the "English" test to fail too!
Clearly the first spec is somehow messing things up for the second spec. But what? And why?
The text was updated successfully, but these errors were encountered: