Moved the check for the rails test environment into rails.rb

This addresses issue #10238. The problem right now is that the ``ENV["RAILS_ENV"]`` variable only gets set to test when you do a ``require rails.all``. This is because the command that checks to see if the Rake tasks are performing tests are only defined there.

I've moved the code that checks for whether rake is running tests into the rails.rb file.

However, I'm stumped as to how to write a test for this. Any input would be welcome!