Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

rake stats bad method count

#1915

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.

Reported by daeltar · February 8th, 2009 @ 07:53 PM

State: duplicate
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. daeltar
    daeltar

    Easy solution seems to be adding

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

    to railties/lib/code_statistics.rb

    February 8th, 2009 @ 08:33 PM

  2. Malte
    Malte
    • 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

    /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/code_statistics.rb

    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...

    March 18th, 2009 @ 07:26 PM

  3. James
    James

    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 Improve class counts for 'rake stats'.

    March 19th, 2009 @ 10:33 PM

  4. Matt Jones
    Matt Jones

    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.

    March 28th, 2009 @ 09:58 PM

  5. Ryan Bigg
    Ryan Bigg
    • State changed from new to duplicate

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

    April 29th, 2010 @ 10:25 PM