Skip to content

Commit f460f26

Browse files
committed
Change the way to calculate root directory
Print out list in alphabetical order Change expectations based in the order of the output
1 parent ff41cfe commit f460f26

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

lib/rails_stats/code_statistics.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def initialize(root_directory)
2020

2121
def to_s
2222
print_header
23-
@statistics.each { |key, stats| print_line(key, stats) }
23+
sorted_keys = @statistics.keys.sort
24+
sorted_keys.each { |key| print_line(key, @statistics[key]) }
2425
print_splitter
2526

2627
print_line("Code", @code_total)

lib/rails_stats/spec_statistics.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def calculate_statistics
3737
out = {}
3838
categorize_files.each do |key, list|
3939
out[key] = Util.calculate_file_statistics(list)
40-
end
40+
end
4141
out
4242
end
4343

lib/rails_stats/test_statistics.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def calculate_statistics
3535
out = {}
3636
categorize_files.each do |key, list|
3737
out[key] = Util.calculate_file_statistics(list)
38-
end
38+
end
3939
out
4040
end
4141

lib/rails_stats/util.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def calculate_shared_projects(shared, *args)
2929
projects[$1] = true
3030
end
3131
end
32-
32+
3333
out = projects.keys
3434

3535
# TODO: make sure none are children of other ones in there
@@ -56,14 +56,14 @@ def calculate_statistics(directories, type = :code, &block)
5656

5757
directories.each do |dir_path|
5858
next unless File.directory?(dir_path)
59-
59+
6060
key = nil
6161
if block_given?
6262
key = yield(dir_path)
6363
end
6464

6565
key = path_to_name(dir_path, is_test) if !key || key.length == 0
66-
66+
6767
out[key] ||= CodeStatisticsCalculator.new(is_test)
6868
out[key].add(calculate_directory_statistics(dir_path))
6969
end

test/lib/rails_stats/code_statistics_test.rb

+8-7
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
+----------------------+---------+---------+---------+---------+-----+-------+
99
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
1010
+----------------------+---------+---------+---------+---------+-----+-------+
11-
| Mailers | 4 | 4 | 1 | 0 | 0 | 0 |
12-
| Models | 3 | 3 | 1 | 0 | 0 | 0 |
13-
| Javascripts | 27 | 7 | 0 | 0 | 0 | 0 |
14-
| Jobs | 7 | 2 | 1 | 0 | 0 | 0 |
15-
| Controllers | 3 | 3 | 1 | 0 | 0 | 0 |
16-
| Helpers | 3 | 3 | 0 | 0 | 0 | 0 |
1711
| Channels | 8 | 8 | 2 | 0 | 0 | 0 |
1812
| Configuration | 417 | 111 | 1 | 0 | 0 | 0 |
13+
| Controllers | 3 | 3 | 1 | 0 | 0 | 0 |
14+
| Helpers | 3 | 3 | 0 | 0 | 0 | 0 |
15+
| Javascripts | 27 | 7 | 0 | 0 | 0 | 0 |
16+
| Jobs | 7 | 2 | 1 | 0 | 0 | 0 |
17+
| Mailers | 4 | 4 | 1 | 0 | 0 | 0 |
18+
| Models | 3 | 3 | 1 | 0 | 0 | 0 |
1919
+----------------------+---------+---------+---------+---------+-----+-------+
2020
| Code | 472 | 141 | 7 | 0 | 0 | 0 |
2121
| Tests | 0 | 0 | 0 | 0 | 0 | 0 |
@@ -26,7 +26,8 @@
2626
EOS
2727

2828
it "outputs useful stats for a Rails project" do
29-
root_directory = File.absolute_path("./test/dummy")
29+
root_directory = File.expand_path('../../../test/dummy', File.dirname(__FILE__))
30+
3031
assert_output(TABLE) do
3132
RailsStats::CodeStatistics.new(root_directory).to_s
3233
end

0 commit comments

Comments
 (0)