michaelreneer/CocoaHelper — pull request #4 by nekno (2013-10-31 00:37:28+00:00)
Title: NSDateFormatter tests pass incorrect dates

When I investigated how Issue #2 passed the unit tests, I discovered it was because it wasn't being tested.

Obviously the NSDateFormatter tests haven't been implemented, or once were implemented and aren't currently working.

The major problem seems to be that the localized strings aren't read from the localized.string files for the iOS static library or the Mac OS framework. Instead of finding the localized string replacements, the name of the string (the key) is used instead, so obviously none of the tests can pass.

So, I used the following solution to ensure the tests passed/failed correctly, but I'm not sure it's an optimal solution.

Essentially the bundle for the XCTest target has no localization.strings files, so when running the unit tests, none of the localized strings are found in the main bundle.

If you instead point the NSDateFormatter extension methods directly to the library's/framework's bundle identifier, then the strings are able to be read out of the localization.strings files in the library's/framework's bundle.

This change produced passing test results for all existing tests (including the ones that were previously commented out) and for new tests I added to test 'tomorrow' and 'yesterday' date strings. The new tests rely on using the English localization strings.

This implementation, however, has the horrific downside of hard-coding the main bundle identifier for the library/framework targets in the NSDateFormatter class extension. If you know of a way to add localization.strings files to the XCTest target it would eliminate the need to change the NSDateFormatter methods. I'm unfamiliar with XCTest, so I couldn't figure it out.