LaunchKit
All quizzes
Rails 0 views

Measuring a Rails app with rake stats

Question

In Ruby on Rails, the rake task in charge of generating a code statistics report of your application is ____.

The correct answer is

Explanation

TL;DR

rake stats (or bin/rails stats in modern Rails) prints a table of code metrics for the application: lines, lines of code, classes, methods, methods per class, and lines of code per method, broken down by directory (app/models, app/controllers, spec or test, and so on). Lines of code exclude blank lines and comments.

Reading the report

The summary line at the bottom is the part worth reading first:

  • Lines of code (test code excluded)
  • Lines of test code
  • Code to test ratio

The ratio is a prompt for questions, not a grade. A ratio below 1:1 (less test code than application code) often signals thin coverage. A very high ratio such as 1:3 is not automatically good either; it can hide slow, redundant, or over-specified tests. Treat stats as a cheap first look at a codebase before reaching for real coverage tooling like SimpleCov.

Version notes

stats started life as a rake task, which is why the classic invocation is rake stats. Rails 5.1 moved the rake tasks behind the rails command, and in current Rails (verified on 8.1) stats is only a Rails command: bin/rails stats works, while bin/rake stats fails with Don't know how to build task 'stats'.

Share this quiz

Comments

No comments yet. Be the first.

Only used to confirm and publish your comment. Never shown publicly, never shared.

Markdown: **bold**, `code`, ```fenced blocks```, > quotes, [links](url). HTML and images are not rendered.