Skip to content

Commit eb3e52b

Browse files
committed
test iteration
1 parent c77d062 commit eb3e52b

File tree

4 files changed

+216
-4
lines changed

4 files changed

+216
-4
lines changed

README.md

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Directory: /path/to/app/
3030

3131
```
3232

33+
3334
### Things it knows about
3435

3536
* Any concepts you've added within an `app` directory
@@ -39,6 +40,201 @@ Directory: /path/to/app/
3940
* Engines and their code
4041
* RSpec/Unit/Cucumber Tests
4142

43+
### Example output
44+
45+
Here are some open source Rails projects an their output.
46+
47+
```bash
48+
$ bundle exec rake stats[/users/brian/examples/diaspora/]
49+
50+
Directory: /users/brian/examples/diaspora
51+
52+
+----------------------+-------+-------+---------+---------+-----+-------+
53+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
54+
+----------------------+-------+-------+---------+---------+-----+-------+
55+
| Collections | 259 | 198 | 0 | 56 | 0 | 1 |
56+
| Helpers | 1863 | 1478 | 0 | 218 | 0 | 4 |
57+
| Models | 4694 | 3517 | 55 | 580 | 10 | 4 |
58+
| Pages | 201 | 158 | 0 | 21 | 0 | 5 |
59+
| Controllers | 2797 | 2168 | 40 | 208 | 5 | 8 |
60+
| Mailers | 313 | 263 | 13 | 32 | 2 | 6 |
61+
| Presenters | 516 | 425 | 18 | 71 | 3 | 3 |
62+
| Uploaders | 84 | 63 | 2 | 9 | 4 | 5 |
63+
| Workers | 600 | 399 | 32 | 33 | 1 | 10 |
64+
| Javascripts | 7550 | 4941 | 0 | 741 | 0 | 4 |
65+
| Libraries | 7031 | 4890 | 69 | 701 | 10 | 4 |
66+
| Configuration | 2556 | 833 | 5 | 10 | 2 | 81 |
67+
| Controller Tests | 4628 | 3775 | 0 | 2 | 0 | 1885 |
68+
| Spec Support | 1141 | 900 | 6 | 56 | 9 | 14 |
69+
| Helper Tests | 771 | 615 | 0 | 6 | 0 | 100 |
70+
| Integration Tests | 891 | 647 | 0 | 14 | 0 | 44 |
71+
| Lib Tests | 4076 | 3259 | 2 | 4 | 2 | 812 |
72+
| Other Tests | 120 | 101 | 0 | 0 | 0 | 0 |
73+
| Mailer Tests | 412 | 328 | 0 | 0 | 0 | 0 |
74+
| Model Tests | 6120 | 4964 | 0 | 1 | 0 | 4962 |
75+
| Presenter Tests | 353 | 303 | 0 | 0 | 0 | 0 |
76+
| Worker Tests | 821 | 648 | 0 | 0 | 0 | 0 |
77+
| Cucumber Features | 2157 | 1863 | 47 | 155 | 3 | 10 |
78+
+----------------------+-------+-------+---------+---------+-----+-------+
79+
| Total | 49954 | 36736 | 289 | 2918 | 10 | 10 |
80+
+----------------------+-------+-------+---------+---------+-----+-------+
81+
Code LOC: 19333 Test LOC: 17403 Code to Test Ratio: 1:0.9
82+
83+
84+
$ bundle exec rake stats[/users/brian/examples/discourse]
85+
86+
Directory: /users/brian/examples/discourse
87+
88+
+----------------------+-------+-------+---------+---------+-----+-------+
89+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
90+
+----------------------+-------+-------+---------+---------+-----+-------+
91+
| Controllers | 5005 | 3812 | 56 | 416 | 7 | 7 |
92+
| Helpers | 286 | 218 | 0 | 32 | 0 | 4 |
93+
| Jobs | 1830 | 1343 | 53 | 114 | 2 | 9 |
94+
| Mailers | 438 | 340 | 7 | 24 | 3 | 12 |
95+
| Models | 12378 | 8393 | 123 | 983 | 7 | 6 |
96+
| Serializers | 2809 | 2223 | 73 | 374 | 5 | 3 |
97+
| Services | 1353 | 1060 | 20 | 106 | 5 | 8 |
98+
| Javascripts | 21722 | 13649 | 0 | 1844 | 0 | 5 |
99+
| Libraries | 35298 | 27521 | 189 | 2565 | 13 | 8 |
100+
| Configuration | 1758 | 1179 | 6 | 12 | 2 | 96 |
101+
| Other Tests | 12998 | 9830 | 20 | 41 | 2 | 237 |
102+
| Controller Tests | 7673 | 5911 | 0 | 4 | 0 | 1475 |
103+
| Spec Support | 707 | 560 | 1 | 16 | 16 | 33 |
104+
| Helper Tests | 88 | 71 | 0 | 0 | 0 | 0 |
105+
| Integration Tests | 307 | 235 | 0 | 1 | 0 | 233 |
106+
| Job Tests | 1343 | 1017 | 3 | 9 | 3 | 111 |
107+
| Mailer Tests | 421 | 302 | 0 | 1 | 0 | 300 |
108+
| Model Tests | 11236 | 8599 | 2 | 49 | 24 | 173 |
109+
| Serializer Tests | 297 | 236 | 0 | 2 | 0 | 116 |
110+
| Service Tests | 1767 | 1406 | 0 | 2 | 0 | 701 |
111+
+----------------------+-------+-------+---------+---------+-----+-------+
112+
| Total | 119714| 87905 | 553 | 6595 | 11 | 11 |
113+
+----------------------+-------+-------+---------+---------+-----+-------+
114+
Code LOC: 59738 Test LOC: 28167 Code to Test Ratio: 1:0.5
115+
116+
117+
$ bundle exec rake stats[/users/brian/examples/gitlabhq]
118+
119+
Directory: /users/brian/examples/gitlabhq
120+
121+
+----------------------+-------+-------+---------+---------+-----+-------+
122+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
123+
+----------------------+-------+-------+---------+---------+-----+-------+
124+
| Controllers | 3690 | 2890 | 66 | 384 | 5 | 5 |
125+
| Finders | 428 | 267 | 8 | 27 | 3 | 7 |
126+
| Helpers | 2280 | 1761 | 0 | 222 | 0 | 5 |
127+
| Mailers | 382 | 275 | 1 | 29 | 29 | 7 |
128+
| Models | 6922 | 4680 | 58 | 714 | 12 | 4 |
129+
| Services | 2021 | 1502 | 51 | 149 | 2 | 8 |
130+
| Uploaders | 81 | 62 | 2 | 14 | 7 | 2 |
131+
| Workers | 128 | 99 | 6 | 8 | 1 | 10 |
132+
| Javascripts | 3843 | 2936 | 1 | 534 | 534 | 3 |
133+
| Libraries | 7246 | 4785 | 120 | 438 | 3 | 8 |
134+
| Configuration | 1421 | 782 | 4 | 11 | 2 | 69 |
135+
| Controller Tests | 428 | 334 | 0 | 0 | 0 | 0 |
136+
| Spec Support | 1119 | 715 | 2 | 27 | 13 | 24 |
137+
| Other Tests | 67 | 55 | 0 | 0 | 0 | 0 |
138+
| Feature Tests | 2209 | 1765 | 0 | 8 | 0 | 218 |
139+
| Finder Tests | 281 | 230 | 0 | 0 | 0 | 0 |
140+
| Helper Tests | 1608 | 1255 | 0 | 5 | 0 | 249 |
141+
| Lib Tests | 1459 | 1180 | 1 | 11 | 11 | 105 |
142+
| Mailer Tests | 630 | 478 | 0 | 0 | 0 | 0 |
143+
| Model Tests | 3856 | 2669 | 0 | 10 | 0 | 264 |
144+
| Request Tests | 4229 | 3600 | 0 | 10 | 0 | 358 |
145+
| Routing Tests | 849 | 520 | 0 | 0 | 0 | 0 |
146+
| Service Tests | 1611 | 1307 | 0 | 34 | 0 | 36 |
147+
| Worker Tests | 45 | 35 | 0 | 2 | 0 | 15 |
148+
| Cucumber Features | 6749 | 5734 | 141 | 947 | 6 | 4 |
149+
| Cucumber Support | 6235 | 4980 | 65 | 71 | 1 | 68 |
150+
+----------------------+-------+-------+---------+---------+-----+-------+
151+
| Total | 59817 | 44896 | 526 | 3655 | 6 | 10 |
152+
+----------------------+-------+-------+---------+---------+-----+-------+
153+
Code LOC: 20039 Test LOC: 24857 Code to Test Ratio: 1:1.2
154+
155+
156+
$ bundle exec rake stats[/users/brian/examples/redmine/]
157+
158+
Directory: /users/brian/examples/redmine
159+
160+
+----------------------+-------+-------+---------+---------+-----+-------+
161+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
162+
+----------------------+-------+-------+---------+---------+-----+-------+
163+
| Controllers | 6738 | 5005 | 51 | 416 | 8 | 10 |
164+
| Helpers | 4445 | 3014 | 2 | 281 | 140 | 8 |
165+
| Models | 13221 | 9369 | 86 | 1026 | 11 | 7 |
166+
| Libraries | 19041 | 13499 | 137 | 1147 | 8 | 9 |
167+
| Configuration | 779 | 550 | 14 | 18 | 1 | 28 |
168+
| Integration Tests | 8286 | 6032 | 92 | 202 | 2 | 27 |
169+
| Other Tests | 669 | 521 | 3 | 53 | 17 | 7 |
170+
| Test Support | 1102 | 791 | 8 | 70 | 8 | 9 |
171+
| Functional Tests | 18448 | 14784 | 61 | 1372 | 22 | 8 |
172+
| Unit Tests | 23680 | 18217 | 117 | 1783 | 15 | 8 |
173+
| Helper Tests | 3321 | 2567 | 16 | 171 | 10 | 13 |
174+
+----------------------+-------+-------+---------+---------+-----+-------+
175+
| Total | 99730 | 74349 | 587 | 6539 | 11 | 9 |
176+
+----------------------+-------+-------+---------+---------+-----+-------+
177+
Code LOC: 31437 Test LOC: 42912 Code to Test Ratio: 1:1.4
178+
179+
180+
$ bundle exec rake stats[/users/brian/examples/refinerycms]
181+
182+
Directory: /users/brian/examples/refinerycms
183+
184+
+----------------------+-------+-------+---------+---------+-----+-------+
185+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
186+
+----------------------+-------+-------+---------+---------+-----+-------+
187+
| Controllers | 950 | 748 | 17 | 83 | 4 | 7 |
188+
| Helpers | 399 | 308 | 0 | 28 | 0 | 9 |
189+
| Mailers | 22 | 18 | 1 | 2 | 2 | 7 |
190+
| Models | 846 | 570 | 14 | 86 | 6 | 4 |
191+
| Presenters | 365 | 271 | 8 | 44 | 5 | 4 |
192+
| Javascripts | 717 | 531 | 0 | 52 | 0 | 8 |
193+
| Libraries | 4 | 4 | 0 | 0 | 0 | 0 |
194+
| Gems | 4166 | 2997 | 44 | 372 | 8 | 6 |
195+
| Controller Tests | 207 | 170 | 1 | 1 | 1 | 168 |
196+
| Spec Support | 309 | 243 | 2 | 6 | 3 | 38 |
197+
| Feature Tests | 1907 | 1484 | 0 | 4 | 0 | 369 |
198+
| Lib Tests | 1952 | 1687 | 6 | 4 | 0 | 419 |
199+
| Model Tests | 1323 | 1072 | 0 | 5 | 0 | 212 |
200+
| Helper Tests | 324 | 264 | 0 | 1 | 0 | 262 |
201+
| Presenter Tests | 355 | 299 | 0 | 0 | 0 | 0 |
202+
+----------------------+-------+-------+---------+---------+-----+-------+
203+
| Total | 13846 | 10666 | 93 | 688 | 7 | 13 |
204+
+----------------------+-------+-------+---------+---------+-----+-------+
205+
Code LOC: 5447 Test LOC: 5219 Code to Test Ratio: 1:1.0
206+
207+
208+
$ bundle exec rake stats[/users/brian/examples/spree]
209+
210+
Directory: /users/brian/examples/spree
211+
212+
+----------------------+-------+-------+---------+---------+-----+-------+
213+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
214+
+----------------------+-------+-------+---------+---------+-----+-------+
215+
| Controllers | 4653 | 3800 | 86 | 492 | 5 | 5 |
216+
| Helpers | 1142 | 949 | 0 | 90 | 0 | 8 |
217+
| Models | 9893 | 7308 | 167 | 973 | 5 | 5 |
218+
| Javascripts | 2770 | 2100 | 9 | 416 | 46 | 3 |
219+
| Mailers | 63 | 58 | 5 | 8 | 1 | 5 |
220+
| Libraries | 15 | 14 | 0 | 0 | 0 | 0 |
221+
| Gems | 4690 | 3641 | 35 | 254 | 7 | 12 |
222+
| Controller Tests | 7344 | 6000 | 6 | 19 | 3 | 313 |
223+
| Model Tests | 16747 | 13452 | 20 | 27 | 1 | 496 |
224+
| Request Tests | 32 | 24 | 0 | 0 | 0 | 0 |
225+
| Spec Support | 577 | 427 | 3 | 9 | 3 | 45 |
226+
| Feature Tests | 6079 | 4809 | 0 | 17 | 0 | 280 |
227+
| Helper Tests | 602 | 470 | 2 | 1 | 0 | 468 |
228+
| Lib Tests | 1455 | 1216 | 8 | 11 | 1 | 108 |
229+
| Mailer Tests | 252 | 208 | 0 | 0 | 0 | 0 |
230+
| Other Tests | 33 | 27 | 0 | 0 | 0 | 0 |
231+
+----------------------+-------+-------+---------+---------+-----+-------+
232+
| Total | 56347 | 44503 | 341 | 2317 | 6 | 17 |
233+
+----------------------+-------+-------+---------+---------+-----+-------+
234+
Code LOC: 17870 Test LOC: 26633 Code to Test Ratio: 1:1.5
235+
236+
```
237+
42238
### TODO
43239

44240
* Option to print out by app directory (stats per engine)

lib/rails_stats/code_statistics.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ def calculate_gem_projects
7676
end
7777

7878
def calculate_spec_projects
79-
specs = Util.calculate_projects(@root_directory, "**", "spec", "spec_helper.rb")
79+
specs = Util.calculate_shared_projects("spec", @root_directory, "**", "spec", "**", "*_spec.rb")
8080
specs.collect do |root_path|
8181
SpecStatistics.new(root_path, @key_concepts)
8282
end
8383
end
8484

8585
def calculate_test_projects
86-
specs = Util.calculate_projects(@root_directory, "**", "test", "test_helper.rb")
87-
specs.collect do |root_path|
86+
tests = Util.calculate_shared_projects("test", @root_directory, "**", "test", "**", "*_test.rb")
87+
tests.collect do |root_path|
8888
TestStatistics.new(root_path, @key_concepts)
8989
end
9090
end

lib/rails_stats/spec_statistics.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ class SpecStatistics
1111
'integrations',
1212
'integration',
1313
'mailers',
14-
'lib']
14+
'lib',
15+
'acceptance',
16+
'factories']
1517

1618
def initialize(directory, key_concepts)
1719
@test = true

lib/rails_stats/util.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ def calculate_projects(*args)
2222
out
2323
end
2424

25+
def calculate_shared_projects(shared, *args)
26+
projects = {}
27+
calculate_projects(*args).each do |path|
28+
if path =~ /(^.*\/#{shared}\/).*/
29+
projects[$1] = true
30+
end
31+
end
32+
33+
out = projects.keys
34+
35+
# TODO: make sure none are children of other ones in there
36+
out
37+
end
38+
2539
def calculate_file_statistics(file, type = :code, &block)
2640
stats = CodeStatisticsCalculator.new
2741

0 commit comments

Comments
 (0)