Adds tests for 'ninja()' in 'commands.py'.

This commit also changes the implementation of 'ninja()' to be somewhat less
ad-hoc, thus making the tests look reasonable instead of written to make the
existing implementation pass.