The problem with TDD is days like this.
I had to do the first big data import for a customer on a brand new system.
The customer was slightly annoyed because, in their eyes, it was late. We were slightly annoyed at that because we’d spent the best part of a week waiting for one of their people to correct the mistakes in the data they had sent us.
I was particularly proud of the test suite for the import routine.
By following the discovery test process, it was neat, nicely segmented across a series of reasonably well-named classes, each of which was easily understood, with clear dependencies to its related classes.
Unlike the previous version of the same code, which was one single class, several thousand lines long, that was practically impossible to trace through.
Each discovery test showed the interdependencies of the classes.
The full stack test took several spreadsheets (standard data, data with references to images, invalid data, data with invalid references to images) and checked that they imported OK.
There were analyser classes that validated the incoming spreadsheet, a transformer class that took a single row and converted the column headings into the correct database field names, an inserter for new products, an updater for existing products, image updaters – it was lovely.
But it all fell to pieces when I ran the customer’s import.
Because there were spaces in the column headings.
Somehow, during configuration, the mapping class’s data source had been mucked up (I’m still not sure how).
The cleaned up data they supplied us with had values in it that they had told us were illegal.
And all the other shit that the real world throws at you.
fill_in 'product_code', with: 'ABC' command was being triggered but it was leaving the field blank. But only sometimes; one time in three.
So remember, it’s not a silver bullet.
In fact, it can be totally deflating when you realise you missed a whole load of edge cases off your tests and were sat there like a smug bastard when in fact you were just as dumb as that idiot on the street corner who gurns for coins.
And then, and only then, PhantomJS decides to piss all over you.