Thursday, January 26, 2012
Working with Rails again
After working with Clojure for the majority of my apprenticeship, I'm now working on a Rails project. The transition has been pretty smooth, but nonetheless it has certainly been a different experience. In may ways, it feels like I am learning Rails all over. In my previous experience with Rails projects I never practiced TDD. So, now I am learning how to write good tests with rspec. Which, as it turns out, is kind of hard in Rails. Also, I'm learning how to write testable (i.e. good) code in Ruby, something I have never done. One of the ways we are attempting to write testable Rails code is abstracting all the actually application logic away from Rails. This is great. It makes it really easy to test the core application logic without being coupled to Rails. What sucks about this is that there really isn't that much core application logic, or at least there is not that much abstracted. The bulk of the application is the UI. Therefore, most of features are implemented with a combination of Haml, Coffee Script and Ruby, wherein lies the difficulty in testing. For each feature, we have to write rspec tests, Jasmine tests, and cucumber acceptance tests. Something about this doesn't sit quite right with me, however, I'm not quite sure why yet. Perhaps I will write a future blog analyzing what about this perturbs me. However, the transition to Rails has made me realize a one things about Clojure development that I took for granted. The Speclj auto runner. Writing tests an getting instant feedback is a complete game changer. I didn't realize this until we started writing tests a few days ago and had to manually run the tests every time we changed something. It was a complete waste of time. So we started using rspec-guard, a nifty gem that auto runs rspec tests upon change. However, this was only a partial solution. After getting guard up and running with our project, I realized that I wasn't getting the instant feedback loop that Speclj provided me. This is because every time guard detects a change, it has to reload the spec helper file, which essentially reloads Rails. So, every time I changed a spec file that has two tests in it, I have to wait 10 seconds for Rails to load. This is huge time waster. I'm guessing that the solution to this problem is to not use Rails, or at least isolate it as much as possible. However, that doesn't seem like too feasible of a solution with the current project I'm working on because as I said previously, there isn't really that much application logic. So, what can I do? Anyways, moving back in to Rails code has been interesting to say the least.