Ruby on Rails:Rake:rake stats没有将我的字段添加到正确的值?

时间:2011-06-22 14:13:27

标签: ruby rake rakefile

在我的rake统计数据修改之前

+----------------------+-------+-------+---------+---------+-----+-------+
| Name                 | Lines |   LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
| Controllers          |  5037 |  3936 |      31 |     292 |   9 |    11 |
| Helpers              |   150 |   128 |       0 |      17 |   0 |     5 |
| Models               |  1523 |  1166 |      42 |     123 |   2 |     7 |
| Libraries            |   633 |   415 |       4 |      65 |  16 |     4 |
| Functional tests     |   289 |   228 |      13 |       0 |   0 |     0 |
| Unit tests           |   560 |   389 |      30 |       0 |   0 |     0 |
| Model specs          |  1085 |   904 |       0 |       3 |   0 |   299 |
| View specs           |    88 |    75 |       0 |       0 |   0 |     0 |
| Controller specs     |   468 |   388 |       0 |       2 |   0 |   192 |
+----------------------+-------+-------+---------+---------+-----+-------+
| Total                |  9833 |  7629 |     120 |     502 |   4 |    13 |
+----------------------+-------+-------+---------+---------+-----+-------+
  Code LOC: 5645     Test LOC: 1984     Code to Test Ratio: 1:0.4

现在,当我添加:

#Factories
::STATS_DIRECTORIES << %w(Factories\ specs test/factories) if File.exist?('test/factories')
::CodeStatistics::TEST_TYPES << "Factory specs" if File.exist?('test/factories')

在第120行附近,它应该增加测试LOC,对吗?

+----------------------+-------+-------+---------+---------+-----+-------+
| Controllers          |  5037 |  3936 |      31 |     292 |   9 |    11 |
| Helpers              |   150 |   128 |       0 |      17 |   0 |     5 |
| Models               |  1523 |  1166 |      42 |     123 |   2 |     7 |
| Libraries            |   633 |   415 |       4 |      65 |  16 |     4 |
| Functional tests     |   289 |   228 |      13 |       0 |   0 |     0 |
| Unit tests           |   560 |   389 |      30 |       0 |   0 |     0 |
| Model specs          |  1085 |   904 |       0 |       3 |   0 |   299 |
| View specs           |    88 |    75 |       0 |       0 |   0 |     0 |
| Controller specs     |   468 |   388 |       0 |       2 |   0 |   192 |
| Factories specs      |   144 |   119 |       0 |       0 |   0 |     0 |
+----------------------+-------+-------+---------+---------+-----+-------+
| Total                |  9977 |  7748 |     120 |     502 |   4 |    13 |
+----------------------+-------+-------+---------+---------+-----+-------+
  Code LOC: 5764     Test LOC: 1984     Code to Test Ratio: 1:0.3

不是从工厂添加144行来测试LOC,而是将它们添加到代码LOC = \ 如何将行数计入Test LOC?

1 个答案:

答案 0 :(得分:2)

您正在向STATS_DIRECTORIES数组添加一个名为“Factories specs”(复数)的内容,但是当您将其添加到TEST_TYPES数组时,您将其称为“Factory specs”(单数) - 所以当rake:stat点击您的test/factories文件夹时,它会在TEST_TYPES中查找“工厂规范”,找不到它,并假定它是代码,而不是测试。你需要在两个地方称它为同一个东西:

::STATS_DIRECTORIES << %w(Factory\ specs test/factories) if File.exist?('test/factories')
::CodeStatistics::TEST_TYPES << "Factory specs" if File.exist?('test/factories')