Reputation: 6645
I confused. What I should test in controller folder? Controller actions for returning success code? Why, if I can do it in integration test by one command? And what for views test? To test if view has some html tags? I can do it in integration tests too.
Models need to test validation rules? Thanks for any help.
Upvotes: 0
Views: 98
Reputation: 15838
I use this guidelines https://github.com/bbatsov/rails-style-guide#rspec
You can have a lot of integration tests but it will be really slow. I like to make a lot of controller, models and views specs and then only a few integration specs.
Upvotes: 0
Reputation: 6805
There are tests easier to implement in a controller spec.
An example:
Scenario: One wants to test authorized access to a set of views (let us assume that non authorized users are to be redirected to a login page).
integration test approach: This can be done testing the view, with integration tests, which tend to be slower to execute (visit login page, fill credential fields and press enter, visit page to test...)
controller test approach: One can test each of controller's methods and check the response code. Was the response a redirect? (code 200). Besides, since the methods in a controller are the entry point of a rails app, one can be positive that additional views are covered by the controller specs.
Upvotes: 1
Reputation: 16720
If you feel confident only with unit (models) and integration specs and it provides enough coverage for your app you can just ignore the others. If you are doing just those two I can tell you that you are doing more then the average developers. And most developers also just use those.
But you should think about controller tests useful when you have a huge app. I mean, in integration tests you should not test http responses or if some text is inside a h1 HTML tag, because if you change the view you will need to change the integration test instead of just changing the view test, if you have one.
There are many kinds of tests so you can have your features breaken in multiple parts and then you can see what's exactly going wrong. Is it on model? Controller?
But totally don't force yourself to write tests you don't feel that are useful to you
Upvotes: 1