New Stuff- Testing
As I mentioned in the previous post, I wanted to write a bit about some of the new things I’ve encountered while working on the application for the tutoring company.
Prior to this, I had used RSpec + Capybara for all of my testing, but the test suite for this application used Test::Unit instead of RSpec. Really, it wasn’t much of a leap, since I had some familiarity with Ruby’s assertions already. I had never combined them with Capybara’s matchers before, though, but it didn’t take long to get comfortable with.
The test suite uses fixtures to generate test data, which was different from the factories-based approach I had seen and used elsewhere. Fixtures are fairly simple though, so again, it didn’t take long to get accustomed to using them.
Functional (controller) specs
While researching functional specs, it became apparent that there’s no consensus on whether they’re necessary, or whether good integration tests would effectively test everything that functional tests would. Although the decision was made to favor integration specs over functional specs when writing future tests, I did get a chance to write a few functional specs to get a feel for them.
Learning about functional specs and reading discussions about their necessity (or lack thereof) gave me a better understanding of testing theory in general, and what should and should not be tested in unit, functional, and integration tests.
Mocking & Stubbing
I’ve read a half-dozen different explanations of how to write tests using mocks and stubs, but the explanation given by Sandi Metz in her book Practical Object-Oriented Design in Ruby (POODR) was by far the clearest and easiest to understand. I’m glad to have a new testing tool at my disposal.
Speaking of POODR, all of Chapter 9 has been immensely helpful in changing how I think about testing. It has also helped me to understand why the tests I’m working with are designed the way they are, and what I should look for when reading tests.
I will probably give this topic a post of its own in the near future, once I’ve got a better handle on it. All I can really say now is that I’ve been able to write integration tests for features that rely on Ajax calls, but it can be tricky. I’ve been using Capybara + Poltergeist. I’ve run into a few difficulties, though, namely a timing issue, which causes a few tests which fail sporadically. I “fixed” this by adding 0.1 second sleep statements at certain points, but I haven’t been able to get a real solution to work yet. I want to get this ironed out soon, though, since expanding integration test coverage is one of the goals for the near future.
Mon 10 Mar 2014