I am writing some tests with RSpec (tests and not specs, the code was untested until now) and have stumbled upon an uncertainty…
I want to know whether a controller is calling the model’s methods properly and I am divided between the possibilities:
- test the controller with stubbing the model method (I won’t know if the model method actually exists or accepts the arguments given)
- leave the model method unstubbed and risk having my controller tests bleed into model test territory (and also make them slow cause of DB access and costly methods)
- write multiple controller tests, each of them leaving unstubbed one model method (still slow as hell but at least it’s verbose)
Is there a correct answer on this?
You could stub the model method if you want, but in general you shouldn’t check in controller test that particular method of a model was called you should check controller’s response content. Don’t forget about black box metaphor.