3 ms·
It's interesting to see how few integration tests there are in Basecamp Next. I used to use functional (controller) tests heavily, but in the last year I've swi
by mhartl 15y ago
It's interesting to see how few integration tests there are in Basecamp Next. I used to use functional (controller) tests heavily, but in the last year I've switched over to integration tests (plus Capybara) for controllers and views. (I still use unit tests for models.) I really like their power and flexibility, and I've found it convenient and intuitive to test, e.g., a web form by visiting the page and (virtually) clicking "Submit". These are the stats for the current Rails Tutorial sample application (taken from the in-progress book at http://railstutorial.org/book?version=3.2 http://railstutorial.org/book?version=3.2):
$ rake stats
+----------------------+-------+-------+---------+---------+-----+-------+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
| Controllers | 164 | 139 | 6 | 23 | 3 | 4 |
| Helpers | 81 | 62 | 0 | 13 | 0 | 2 |
| Models | 102 | 58 | 3 | 6 | 2 | 7 |
| Libraries | 0 | 0 | 0 | 0 | 0 | 0 |
| Model specs | 256 | 198 | 0 | 0 | 0 | 0 |
| Controller specs | 29 | 22 | 0 | 0 | 0 | 0 |
| Request specs | 555 | 424 | 0 | 3 | 0 | 139 |
| Cucumber features | 87 | 34 | 0 | 0 | 0 | 0 |
+----------------------+-------+-------+---------+---------+-----+-------+
| Total | 1274 | 937 | 9 | 45 | 5 | 18 |
+----------------------+-------+-------+---------+---------+-----+-------+
Code LOC: 259 Test LOC: 678 Code to Test Ratio: 1:2.6
(Note that "Request specs" is RSpec-speak for "Integration tests".) This is probably a little heavier on the test code side than I would have in an app designed for production rather than pedagogy, but it gives you the basic idea.
Even though there's some minor controversy about testing frameworks in the Ruby community (you can see that I use—gasp!—RSpec), I think it's great that the only way to cause major testing controversy is not to do it.
P.S. I have some reservations about Cucumber, and the Cucumber features are there mainly for Rails Tutorial readers who want a quick introduction to the subject. I don't use Cucumber much myself, although I do have a better appreciation of its virtues than I used to.