1

在我的 rake stats 修改之前

+----------------------+-------+-------+---------+---------+-----+-------+
| 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 =\ 我如何让行数在测试 LOC 中?

4

1 回答 1

2

您正在向数组中添加称为“工厂规格”(复数)的东西STATS_DIRECTORIES,但是当您将其添加到TEST_TYPES数组时,您将其称为“工厂规格”(单数) - 所以当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')
于 2011-06-22T14:48:12.527 回答