Check directory existence using "test -d" instead of "ls".

We are interested in directory existence, not its content. Although I
did not performed any benchmarks, I believe, that "test -d" should be
more effective.

Note: I did tested only the test suite change and change in rails.yaml, but since the usage in other places is similar, I believe they works.