Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Make rake task for code statistics handle new test locations properly #8466

Merged
merged 1 commit into from Dec 9, 2012

Conversation

Projects
None yet
4 participants
Member

georgeclaghorn commented Dec 9, 2012

As of 2a68f68:

  • Unit tests are now in test/models, instead of test/units
  • Functional tests are now in test/controllers, instead of
    test/functional
  • Helper tests are now in test/helpers, instead of test/units/helpers
  • Mailer tests are now in test/mailers, instead of test/functional

Update the rake task for code statistics (rake stats) so that it recognizes files in the above locations as tests, and accurately calculates statistics such as "Test LOC" and "Code to Test Ratio." Safely handle Rails apps that still have tests in the old locations.

In a Rails 4 app running master, with one model and two corresponding model tests in the new location, the output of rake stats is as follows:

+----------------------+-------+-------+---------+---------+-----+-------+
| Name                 | Lines |   LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
| Controllers          |     5 |     3 |       1 |       0 |   0 |     0 |
| Helpers              |     2 |     2 |       0 |       0 |   0 |     0 |
| Models               |    17 |    13 |       1 |       2 |   2 |     4 |
| Mailers              |     0 |     0 |       0 |       0 |   0 |     0 |
| Javascripts          |    16 |     0 |       0 |       0 |   0 |     0 |
| Libraries            |     0 |     0 |       0 |       0 |   0 |     0 |
| Controller tests     |     0 |     0 |       0 |       0 |   0 |     0 |
| Helper tests         |     0 |     0 |       0 |       0 |   0 |     0 |
| Model tests          |    15 |    11 |       1 |       0 |   0 |     0 |
| Mailer tests         |     0 |     0 |       0 |       0 |   0 |     0 |
| Integration tests    |     0 |     0 |       0 |       0 |   0 |     0 |
+----------------------+-------+-------+---------+---------+-----+-------+
| Total                |    55 |    29 |       3 |       2 |   0 |    12 |
+----------------------+-------+-------+---------+---------+-----+-------+
  Code LOC: 29     Test LOC: 0     Code to Test Ratio: 1:0.0

Note that Test LOC is incorrectly reported as 0 and Code-to-Test Ratio is incorrectly reported as 1:0.0.

In the same Rails 4 app running with my rake stats updates:

+----------------------+-------+-------+---------+---------+-----+-------+
| Name                 | Lines |   LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
| Controllers          |     5 |     3 |       1 |       0 |   0 |     0 |
| Helpers              |     2 |     2 |       0 |       0 |   0 |     0 |
| Models               |    17 |    13 |       1 |       2 |   2 |     4 |
| Mailers              |     0 |     0 |       0 |       0 |   0 |     0 |
| Javascripts          |    16 |     0 |       0 |       0 |   0 |     0 |
| Libraries            |     0 |     0 |       0 |       0 |   0 |     0 |
| Controller tests     |     0 |     0 |       0 |       0 |   0 |     0 |
| Helper tests         |     0 |     0 |       0 |       0 |   0 |     0 |
| Model tests          |    15 |    11 |       1 |       0 |   0 |     0 |
| Mailer tests         |     0 |     0 |       0 |       0 |   0 |     0 |
| Integration tests    |     0 |     0 |       0 |       0 |   0 |     0 |
+----------------------+-------+-------+---------+---------+-----+-------+
| Total                |    55 |    29 |       3 |       2 |   0 |    12 |
+----------------------+-------+-------+---------+---------+-----+-------+
  Code LOC: 18     Test LOC: 11     Code to Test Ratio: 1:0.6

Test LOC is now correctly reported as 11 and Code-to-Test Ratio is correctly reported as 1:0.6.

/cc @carlosantoniodasilva

Make code statistics rake task handle new test locations properly
As of 2a68f68:

- Unit tests are now in test/models, instead of test/units
- Functional tests are now in test/controllers, instead of
  test/functional
- Helper tests are now in test/helpers, instead of test/units/helpers
- Mailer tests are now in test/mailers, instead of test/functional

Update the rake task for code statistics (`rake stats`) so that it
recognizes files in the above locations as tests, and accurately
calculates statistics such as "Test LOC" and "Code to Test Ratio."
Safely handle Rails apps that still have tests in the old locations.
Member

georgeclaghorn commented Dec 9, 2012

Updated version of #8463.

jeremy added a commit that referenced this pull request Dec 9, 2012

Merge pull request #8466 from gclag/stats-handle-new-test-locations
Make rake task for code statistics handle new test locations properly

@jeremy jeremy merged commit e58e8bd into rails:master Dec 9, 2012

Member

steveklabnik commented Dec 9, 2012

Thanks! You don't need to open new pull request, by the way, just force push to the branch and GitHub updates the new ones.

Awesome, thanks!

Member

georgeclaghorn commented Dec 9, 2012

@steveklabnik Okay, thanks! Didn't know that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment