This is Part 4 of the preview for the "Keeping Tests Dry" I will be giving at erubycon tomorrow.
One issue with the previous three codeexamples is that they are testing ActiveRecord. This is unnecessary: ActiveRecord has its own tests, and I already believe that validations work as advertised.
We can use mocks to simply verify that validations are called with the correct arguments. The only tricky thing is that we are mocking class level behavior that happens when the file is read. To avoid dependencies on other tests, we will read the file again in its own module:
What do you think? I would be interested to see the Groovy equivalent.
We are a collection of experienced, thoughtful technologists, passionate about helping organizations deploy
technology effectively and humanely to build better futures. We like to work with you on the hard stuff.