I am currently beginning with BDD - I have not written any tests before. I always try to keep my models fat and my controllers skinny.
What do you think - are controller specs necessary?
Best regards
I am currently beginning with BDD - I have not written any tests before. I always try to keep my models fat and my controllers skinny.
What do you think - are controller specs necessary?
Best regards
Yes. Test the correct calls are being made, and that the correct redirects and being made when necessary, and test that the correct pages are being rendered. So test that your application behaves as expected.
For myself I'm trying to understand the balance between seeking high levels of code coverage in testing and the long term cost of maintaing a set of tests that may be quite brittle.
Suppose we have a Controller that goes
try {
result = mode.doSomething();
if (result.count == 0 )
message = "none found"
redisplay criterion page
else if (result.count == 1 )
display detail page
else
display list page
} catch exception {
message = "bad things happened, please try again"
redisplay criterion page
}
A tentative thought is is that tests of the three count cases (0, 1, many) may be less valuable, and more prone to change than the test of the exeption case. Less valuable because a). other testing will catch problems in page display b). the test gets very close to simply reproducing the code.
code: go to page X
test: did you go to page X?
If the developer makes the wrong choice of X he gets the test wrong too! If usability testing of the UI reveals that Y is better page to display then we update the code and the test in tandem. Did the test really achieve anything?
Whereas the exception case may be very hard to exercise in normal UI testing, and really easy to test with mocks. And, behaviour following exceptions is something that we really do need to get right.
What do you think - are controller specs necessary?
I don't think they are necessary if you combine them with a good integration test. I find the usability of the application very important, so for every change in controller / views, I click through the application and find out how it feels. Creating 'dumb' tests for controllers and views doesn't have much extra value in my opinion.
For integration testing I'm using Cucumber. This makes it possible to test the full stack and make sure your application performs in the way you want. For the business logic (the fat models) I still use RSpec.