February 2018
Intermediate to advanced
406 pages
9h 52m
English
Rails provides built-in functionality for associations and validations, which leads to questions about how to effectively and usefully test those features in your application.
The answer in both cases is similar, and goes back to the basic principle that we’re testing functionality and not implementation. Although I do not normally write tests just to show the existence of a particular association or validation, I do sometimes write tests that show those features in action. For associations, this means showing the association in use. For validations, it means testing the overall logic of what makes an instance valid.
The testing gem shoulda-matchers defines matchers that specifically test for the existence of validations ...