Friday, April 24, 2009

Don't Mix Your Mocks!

Yesterday while pairing with Jake Scruggs we came across the strangest problem. We added in some tests for a new component that we were adding, and were going to check the new code in. And what do you do before you check in boys and girls? That's right! You run your specs. So we run the specs and all of a sudden there are two failing tests. Wait....what? Those tests aren't even near anything we changed

So we did the poor man's roll back by commenting out every line of code that we had changed, and ran the specs again. Still two failures. We did some rubber ducking with Dave Hoover, who tried to just comment out the failing specs. We ran the tests again...Now there were 8 failures. What the What? Commented those back in....and now we have a total of 10 failures. We had everyone on the project get up to date and run the specs. Every single person had a different number of failing tests.

It came down to the fact that somehow we had two different mocking frameworks in place. We had some rspec tests, and we had some mocha tests. They lived in harmony for a long time and then all of a sudden...KABOOOOM. The tests looked like they were trying to overwrite class methods and so I guess the two different fameworks started bumping heads. We moved everything to the rspec mocking model and everything was back to playing nice.

So. In short. Make sure you keep an eye on what mocking framework is being used in your project and stick with it. Strange erros indeed!