I'm not thrilled about Rails' use of global variables for everything. Model classes find the database connection through a global variable (ActiveRecord::Base.connection
), there is the Rails
class which is a global access point for things like the logger, the current environment, for caching, etc. ActionMailer
makes global variables out of your mailers, and so on and so forth. Rails is built around the use of global variables, so that whatever you do, at any level of the application, you can always reach for a global variable.
This makes testing ugly. If Rails was built on Java, it would make testing really, really hard, but since it's Ruby it just gets ugly. Tests need to stub out a lot of global context in order to run in isolation, and that can easily make tests seem nonsensical. It's not uncommon to see five or ten lines of code that stubs out different global variables, followed by one or two lines of actual test. It's not that five or ten lines of setup for a test is a problem, but without reading the code under test you can't easily see what impact the global state will have, and how it is significant. This makes many tests unnecessarily ugly.
I find it a bit ironic that the Rails community is the most test savvy of any that I've been part of.
Having said that I wouldn't trade Rails for anything that is currently available. The speed at which you can get things done, and the huge number of plugins and gems that removes all the tedious work just blows me away every day.