Fix gem presence testing.

Incorporates the changes in c1bac44b.