diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..f892ef6 --- /dev/null +++ b/.github/workflows/test.yml @@ -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 \ No newline at end of file diff --git a/lib/rails_stats/code_statistics.rb b/lib/rails_stats/code_statistics.rb index 5229ffd..bc2ec74 100644 --- a/lib/rails_stats/code_statistics.rb +++ b/lib/rails_stats/code_statistics.rb @@ -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) diff --git a/lib/rails_stats/spec_statistics.rb b/lib/rails_stats/spec_statistics.rb index b7415cf..f8edda3 100644 --- a/lib/rails_stats/spec_statistics.rb +++ b/lib/rails_stats/spec_statistics.rb @@ -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 diff --git a/lib/rails_stats/test_statistics.rb b/lib/rails_stats/test_statistics.rb index 2cf0a11..927a998 100644 --- a/lib/rails_stats/test_statistics.rb +++ b/lib/rails_stats/test_statistics.rb @@ -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 diff --git a/lib/rails_stats/util.rb b/lib/rails_stats/util.rb index 17c4abe..bbe0d39 100644 --- a/lib/rails_stats/util.rb +++ b/lib/rails_stats/util.rb @@ -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 @@ -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 diff --git a/rails_stats.gemspec b/rails_stats.gemspec index 6e452f3..28fe705 100644 --- a/rails_stats.gemspec +++ b/rails_stats.gemspec @@ -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 diff --git a/test/lib/rails_stats/code_statistics_test.rb b/test/lib/rails_stats/code_statistics_test.rb index f4a855a..bfdd6ab 100644 --- a/test/lib/rails_stats/code_statistics_test.rb +++ b/test/lib/rails_stats/code_statistics_test.rb @@ -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 | @@ -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 diff --git a/test/test_helper.rb b/test/test_helper.rb index aa4e4e5..0e84dab 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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"