Skip to content

Commit 82a963c

Browse files
authored
Merge pull request #18 from fastruby/enable-simplecov-and-codecov
Enable simplecov and codecov
2 parents 638b081 + 96bf12c commit 82a963c

File tree

8 files changed

+125
-13
lines changed

8 files changed

+125
-13
lines changed

.github/workflows/test.yml

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# .github/workflows/ci.yml
2+
3+
name: Test
4+
on:
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
branches:
10+
- main
11+
env:
12+
COVERAGE: true
13+
CODECOV_TOKEN: d7028c0e-97c5-485f-85e5-f63daabeef63
14+
jobs:
15+
test-ruby-2-4-x:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v1
20+
- name: Setup Ruby
21+
uses: ruby/setup-ruby@v1
22+
with:
23+
ruby-version: 2.4
24+
bundler-cache: true
25+
- name: Build and run tests
26+
run: |
27+
gem install bundler
28+
bundle install --jobs 4 --retry 3
29+
bundle exec rake test
30+
test-ruby-2-5-x:
31+
runs-on: ubuntu-latest
32+
33+
steps:
34+
- uses: actions/checkout@v1
35+
- name: Setup Ruby
36+
uses: ruby/setup-ruby@v1
37+
with:
38+
ruby-version: 2.5
39+
bundler-cache: true
40+
- name: Build and run tests
41+
run: |
42+
gem install bundler
43+
bundle install --jobs 4 --retry 3
44+
bundle exec rake test
45+
test-ruby-2-6-x:
46+
runs-on: ubuntu-latest
47+
48+
steps:
49+
- uses: actions/checkout@v1
50+
- name: Setup Ruby
51+
uses: ruby/setup-ruby@v1
52+
with:
53+
ruby-version: 2.6
54+
bundler-cache: true
55+
- name: Build and run tests
56+
run: |
57+
gem install bundler
58+
bundle install --jobs 4 --retry 3
59+
bundle exec rake test
60+
test-ruby-2-7-x:
61+
runs-on: ubuntu-latest
62+
63+
steps:
64+
- uses: actions/checkout@v1
65+
- name: Setup Ruby
66+
uses: ruby/setup-ruby@v1
67+
with:
68+
ruby-version: 2.7
69+
bundler-cache: true
70+
- name: Build and run tests
71+
run: |
72+
gem install bundler
73+
bundle install --jobs 4 --retry 3
74+
bundle exec rake test
75+
test-ruby-3-0-x:
76+
runs-on: ubuntu-latest
77+
78+
steps:
79+
- uses: actions/checkout@v1
80+
- name: Setup Ruby
81+
uses: ruby/setup-ruby@v1
82+
with:
83+
ruby-version: 3.0
84+
bundler-cache: true
85+
- name: Build and run tests
86+
run: |
87+
gem install bundler
88+
bundle install --jobs 4 --retry 3
89+
bundle exec rake test

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

rails_stats.gemspec

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ Gem::Specification.new do |spec|
2121
spec.add_dependency "rake"
2222
spec.add_development_dependency "bundler", ">= 1.6", "< 3.0"
2323
spec.add_development_dependency "byebug"
24+
spec.add_development_dependency "codecov"
2425
spec.add_development_dependency "minitest"
2526
spec.add_development_dependency "minitest-around"
27+
spec.add_development_dependency "simplecov"
28+
spec.add_development_dependency "simplecov-console"
2629
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

test/test_helper.rb

+18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
# frozen_string_literal: true
22

3+
if ENV["COVERAGE"] == "true"
4+
require "simplecov"
5+
require "simplecov-console"
6+
require "codecov"
7+
8+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
9+
SimpleCov::Formatter::HTMLFormatter,
10+
SimpleCov::Formatter::Console,
11+
SimpleCov::Formatter::Codecov,
12+
]
13+
14+
SimpleCov.start do
15+
track_files "lib/**/*.rb"
16+
end
17+
18+
puts "Using SimpleCov v#{SimpleCov::VERSION}"
19+
end
20+
321
require "byebug"
422

523
require "minitest/autorun"

0 commit comments

Comments
 (0)