Rails rspec controller test against integration test

I just finished writing a detailed integration of rspec capybara and unit tests for a Rails application, which includes the mocking username Omniauth (twitter), filling out forms, validating data, etc. However, I am wondering if I need to write a separate controller or a functional test.

Will appreciate your input and any links to further readings, etc.

+6
source share
2 answers

I will play the devil's advocate here, since I know that I am probably in the minority with this opinion: I really prefer to do extremely thorough controller testing. A few reasons:

1) It’s easier for me to systematically check every path and result at the controller level than at the integration testing level. My integration tests are, first of all, only happy paths and some of the most common error paths.

2) At the controller level, there are many potential security issues. Thorough testing helps me ensure that nothing malicious can go through my model logic.

3) This is subjective, but it really makes me think of some of the long-tailed paths that my application can go through. What if someone tries to use an invalid reset token in the url? Testing the controller ensures that I consider all options.

4) Unlike integration tests, they are fairly straightforward to test. Every action is just a ruby ​​method!

+10
source

Personally, I think that if your request (integration) implements all the code paths that you cover. Ryan Bates has an excellent Railscast about how he tests here: http://railscasts.com/episodes/275-how-i-test?autoplay=true and around 5:05, he talks about a similar thing. Like you, I like to write integration tests, not controller specifications. Most time controllers simply run operations like CRUD (especially if you are careful not to allow domain logic from the controller), so all you are testing is forests.

+6
source

All Articles