Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable simplecov and codecov #18

Merged
merged 5 commits into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# .github/workflows/ci.yml

name: Test
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
COVERAGE: true
CODECOV_TOKEN: d7028c0e-97c5-485f-85e5-f63daabeef63
jobs:
test-ruby-2-4-x:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.4
bundler-cache: true
- name: Build and run tests
run: |
gem install bundler
bundle install --jobs 4 --retry 3
bundle exec rake test
test-ruby-2-5-x:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.5
bundler-cache: true
- name: Build and run tests
run: |
gem install bundler
bundle install --jobs 4 --retry 3
bundle exec rake test
test-ruby-2-6-x:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
bundler-cache: true
- name: Build and run tests
run: |
gem install bundler
bundle install --jobs 4 --retry 3
bundle exec rake test
test-ruby-2-7-x:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
bundler-cache: true
- name: Build and run tests
run: |
gem install bundler
bundle install --jobs 4 --retry 3
bundle exec rake test
test-ruby-3-0-x:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0
bundler-cache: true
- name: Build and run tests
run: |
gem install bundler
bundle install --jobs 4 --retry 3
bundle exec rake test
3 changes: 2 additions & 1 deletion lib/rails_stats/code_statistics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def initialize(root_directory)

def to_s
print_header
@statistics.each { |key, stats| print_line(key, stats) }
sorted_keys = @statistics.keys.sort
sorted_keys.each { |key| print_line(key, @statistics[key]) }
print_splitter

print_line("Code", @code_total)
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_stats/spec_statistics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def calculate_statistics
out = {}
categorize_files.each do |key, list|
out[key] = Util.calculate_file_statistics(list)
end
end
out
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rails_stats/test_statistics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def calculate_statistics
out = {}
categorize_files.each do |key, list|
out[key] = Util.calculate_file_statistics(list)
end
end
out
end

Expand Down
6 changes: 3 additions & 3 deletions lib/rails_stats/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def calculate_shared_projects(shared, *args)
projects[$1] = true
end
end

out = projects.keys

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

directories.each do |dir_path|
next unless File.directory?(dir_path)

key = nil
if block_given?
key = yield(dir_path)
end

key = path_to_name(dir_path, is_test) if !key || key.length == 0

out[key] ||= CodeStatisticsCalculator.new(is_test)
out[key].add(calculate_directory_statistics(dir_path))
end
Expand Down
3 changes: 3 additions & 0 deletions rails_stats.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Gem::Specification.new do |spec|
spec.add_dependency "rake"
spec.add_development_dependency "bundler", ">= 1.6", "< 3.0"
spec.add_development_dependency "byebug"
spec.add_development_dependency "codecov"
spec.add_development_dependency "minitest"
spec.add_development_dependency "minitest-around"
spec.add_development_dependency "simplecov"
spec.add_development_dependency "simplecov-console"
end
15 changes: 8 additions & 7 deletions test/lib/rails_stats/code_statistics_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
+----------------------+---------+---------+---------+---------+-----+-------+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
+----------------------+---------+---------+---------+---------+-----+-------+
| Mailers | 4 | 4 | 1 | 0 | 0 | 0 |
| Models | 3 | 3 | 1 | 0 | 0 | 0 |
| Javascripts | 27 | 7 | 0 | 0 | 0 | 0 |
| Jobs | 7 | 2 | 1 | 0 | 0 | 0 |
| Controllers | 3 | 3 | 1 | 0 | 0 | 0 |
| Helpers | 3 | 3 | 0 | 0 | 0 | 0 |
| Channels | 8 | 8 | 2 | 0 | 0 | 0 |
| Configuration | 417 | 111 | 1 | 0 | 0 | 0 |
| Controllers | 3 | 3 | 1 | 0 | 0 | 0 |
| Helpers | 3 | 3 | 0 | 0 | 0 | 0 |
| Javascripts | 27 | 7 | 0 | 0 | 0 | 0 |
| Jobs | 7 | 2 | 1 | 0 | 0 | 0 |
| Mailers | 4 | 4 | 1 | 0 | 0 | 0 |
| Models | 3 | 3 | 1 | 0 | 0 | 0 |
+----------------------+---------+---------+---------+---------+-----+-------+
| Code | 472 | 141 | 7 | 0 | 0 | 0 |
| Tests | 0 | 0 | 0 | 0 | 0 | 0 |
Expand All @@ -26,7 +26,8 @@
EOS

it "outputs useful stats for a Rails project" do
root_directory = File.absolute_path("./test/dummy")
root_directory = File.expand_path('../../../test/dummy', File.dirname(__FILE__))

assert_output(TABLE) do
RailsStats::CodeStatistics.new(root_directory).to_s
end
Expand Down
18 changes: 18 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# frozen_string_literal: true

if ENV["COVERAGE"] == "true"
require "simplecov"
require "simplecov-console"
require "codecov"

SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::Console,
SimpleCov::Formatter::Codecov,
]

SimpleCov.start do
track_files "lib/**/*.rb"
end

puts "Using SimpleCov v#{SimpleCov::VERSION}"
end

require "byebug"

require "minitest/autorun"
Expand Down