[EN] Controller Testing: You’re Doing It Wrong
How do you feel about your controller testing strategy? Do you feel begrudgingly obligated to write them? Do you find yourself stubbing methods like
find_by only to feel a vague sense of dissatisfaction? Is your test suite soul-crushingly slow because you’re relying on integration specs to test controllers? Do you write controller specs at all?
Rails controllers are wonderfully idiomatic and declarative to the point of being almost redundant. This is a good thing; it keeps many concerns like authentication and server response consistent while keeping business logic in models where it belongs. But this same simplicity leaves many developers conflicted about how and what to test in controller specs. To properly test Rails controllers we need a testing strategy as declarative as the controllers themselves. Come find out how to write controller specs that are as simple and concise as well written Rails controllers!
- Groundwork Software
- Job title
- Software Mentor
Jonathan Mukai-Heidt is a founding partner at Groundwork, a new mentorship-focused Rails consultancy in New York City.
- Brooklyn NY