Posts for category: rails envy
Testing Practices Interview 3: Gregg Pollack
Next up in the Testing Practices interview series is Gregg Pollack. Gregg is one of the proprietors of Rails Envy, and is one of the co-hosts of their Rails Envy Podcast, which mentioned Rails Prescriptions today—thanks Gregg!
Gregg is also one of the founding members of the Rails Activists. He’s also done a lot of video production, including some excellent ruby and rails screencasts, and his series condensing various Ruby and Rails conferences. Put it all that way, and he seems kind of busy, actually…
Take it away, Gregg…
How did you get into writing tests regularly? Did you have a specific moment when you realized automated testing was valuable?
I have to admit, my first 3 Rails projects didn’t contain any tests. I got into testing when RSpec started on the scene. RSpec just made more sense and the documentation on the RSpec website was really useful. Once I figured out how to use RSpec with autotest and growl, testing became much more fun.
I also ended up doing a talk at my local users group about how I came to love testing. It’s a little dated, but still quite relevant:
http://www.railsenvy.com/2007/10/4/how-i-learned-to-love-testing-presentation
What is your Rails testing process? What kinds of tests do you write, and what tools do you use to write them?
I used to write isolated tests at the model and controller level using RSpec, properly mocking and stubbing at the controller level. Often times integration tests would get ignored.
Currently I’m working on a project using Shoulda for Model tests and Integration tests with Webrat. Yes, we’re not doing controller or view tests. So far I’m really liking the combination, and it seems to cover things pretty well without having to deal with much mocking and stubbing of controllers/view tests which have very little logic anyways.
What’s the most interesting thing you’ve discovered about testing recently?
Webrat rocks for integration tests.
Is there a tool you wish you had for testing, but which you don’t think currently exists?
Hmmm.. James Golick recently blogged about one line tests using a library called Zebra. He also argues that test names are essentially comments, and well.. too many comments are a code smell.
So what’s the alternative?
Creating a DSL that allows us to write tests in a way that doesn’t need names/comments. Shoulda gets us pretty close with all of it’s one line helpers like:
should_belong_to :user should_have_many :tags, :through => :taggings should_require_unique_attributes :title should_require_attributes should_only_allow_numeric_values_for :user_id
None of these tests need comments to figure out what they’re testing! I’d love to figure out a way to do more of this, and the Zebra library James put out is certainly a step in the right direction.
What advice would you give somebody looking to write more effective tests?
Integration tests are probably more important then anything else, and using a library like Webrat makes them very easy to do.
If you’re working with a team of people and you want to ensure you’re building a solid test library then a Continuous Integration server is imperative. Set it to run all your tests every time something is checked in and if it fails to email everyone. Make a rule that whoever checks in code that causes tests to fail has to buy everyone a round of beer, or has to perform some humiliating task. Checked in code that fails should be fixed immediately.


