This project is archived and is in readonly mode.

#1915 ✓duplicate

rake stats bad method count

Reported by daeltar | February 8th, 2009 @ 07:53 PM | in 2.x

When using block syntax for tests(e.g.. test "something" do ... ) instead of method calls(e.g.. def test_something) you get bad result by running rake stats

example output:

| Name                 | Lines |   LOC | Classes | Methods | M/C | LOC/M |
| Integration tests    |    40 |    33 |       1 |       4 |   4 |     6 |
| Functional tests     |   257 |   214 |       8 |       2 |   0 |   105 |

Suggested behavior is to count test "something" do blocks as methods in this report.

Comments and changes to this ticket

  • daeltar

    daeltar February 8th, 2009 @ 08:33 PM

    Easy solution seems to be adding

                     stats["methods"]   += 1 if line =~ /test \"[a-z]/

    to railties/lib/code_statistics.rb

  • Malte

    Malte March 18th, 2009 @ 07:26 PM

    • Tag changed from rake to 2.3.2, rake, stats

    Hi, this issue persists in in 2.3.2 (of course). Daeltar, your patch looks ok, but it doesn't work for me- patched


    but still no test-stats. Maybe rake is not using this gem-directory? (I have some older versions installed, too but 2.3.2 is configured in environment.rb and app uses it with script/console etc.) Any ideas? Sorry if this is not the right place to discuss this...

  • James

    James March 19th, 2009 @ 10:33 PM

    You might want to try a slightly more stringent regex, something like...

    stats["methods"] += 1 if line =~ /test ("(\\.|[^"\\])*"|'(\\.|[^'\\])*') do /

    Related: I've submitted a patch to improve class counts so that classes that are opened in several files aren't counted more than once -- see #2299.

  • Matt Jones

    Matt Jones March 28th, 2009 @ 09:58 PM

    I noticed this as well a while back, but I'm not sure what the utility of making changes to the task is - at best, it's a very rough count.

    Catching 'test "blah"' lines is a good start, but what about Shoulda tests? Rspec? (and others...) Nevermind issues with code that dynamically defines methods and so forth.

  • Ryan Bigg

    Ryan Bigg April 29th, 2010 @ 10:25 PM

    • State changed from “new” to “duplicate”

    I agree with Matt Jones, it's a rough count and something that won't be fixed.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket