Quote:
Originally Posted by RICHI8
I want to start with a kudos for writing tests.
I'm not that fond of Controller/Functional tests basically for this very reason:
Web applications contain a ton of context and setup. Controller/Functional specs can have so many paths that you can possibly take due to this and this is what leads to big, slow and hard to maintain test suites. Every time you add a new logical branch you now have another fork that you have to test for in N amount of places. Yikes, that sure gets out of hand quickly.
Try just writing Acceptance tests that follow the "happy path" that a User would go through. Also cover "unhappy paths" for mission critical tasks. Anything that a User will navigate in the UI belongs in an Acceptance and if you have some important non-UI tasks you can put those in a Request spec.
For even more testing boners: Write your tests first following an Outside-In pattern of: Acceptance -> Unit -> Implementation -> Refactor.
I agree that controller tests are of somewhat limited value, in particular because you'll have a ton of controllers and a ton of potential outcomes for each controller. The one I did test was one that had very complicated authorization logic, and would have required several different users of different roles to interact.
We're also not bothering to wire up the views right now because we have a UI guy coming in to redo the whole design/flow next week (we're a 3 person company, and I'm doing basically 90% of the site right now while we look for more people). So in this case I spent a bit of extra time on one controller spec, and am not 100% confident that it's secure/functional when we do go in and implement the views.
I don't imagine I'll have too too many controller specs, but will probably test some of the more complicated ones for certain actions.
I like the approach you laid out in the end. Once we have the flow laid out, I'll throw down a few feature/request specs. And of course we'll test the models thoroughly.
I look forward to refining my method of testing as we go forward (as I'm literally 8 days into my first full time rails job and I feel like I've learned a ton already). I can see how unbelievably valuable they are though even with a small suite.