Fix lookup bug for multiple registries.

Improve and fix tests.

//cc @svnlto 

There are still some strange things such as abusing beforeEach and afterEach when after and before should be more appropriate.