Skip to content

Commit

Permalink
Merge pull request #206 from grodowski/ruby-3.3.0
Browse files Browse the repository at this point in the history
Ruby 3.3.0
  • Loading branch information
grodowski authored Jan 9, 2024
2 parents 4cfbdf2 + 3ade254 commit 1f6df58
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby: ['3.2', '3.0', '2.7']
ruby: ['3.3', '3.0']
steps:
- uses: actions/checkout@v3
with:
Expand Down
3 changes: 2 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
AllCops:
NewCops: enable
TargetRubyVersion: 2.7.0
TargetRubyVersion: 3.0
Exclude:
- spec/fixtures/**/*
SuggestExtensions: false

Style/RegexpLiteral:
EnforcedStyle: slashes
Expand Down
10 changes: 10 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@
source 'https://rubygems.org'

gemspec

gem 'bundler'
gem 'pry'
gem 'rake', '~> 13.0'
gem 'rspec', '~> 3.0'
gem 'rubocop'
gem 'simplecov'
gem 'simplecov-html'
gem 'simplecov-lcov', '~> 0.8'
gem 'timecop'
4 changes: 2 additions & 2 deletions lib/undercover/changeset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ def each_changed_line
end

# TODO: refactor to a standalone validator (depending on changeset AND lcov)
# TODO: add specs
def validate(lcov_report_path)
return :no_changes if files.empty?
return :stale_coverage if last_modified > File.mtime(lcov_report_path)

:stale_coverage if last_modified > File.mtime(lcov_report_path)
end

private
Expand Down
12 changes: 6 additions & 6 deletions lib/undercover/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ def to_s
def formatted_warnings
@results.map.with_index(1) do |res, idx|
"🚨 #{idx}) node `#{res.node.name}` type: #{res.node.human_name},\n" +
(' ' * pad_size) + "loc: #{res.file_path_with_lines}," \
" coverage: #{res.coverage_f * 100}%\n" +
(' ' * pad_size) + "loc: #{res.file_path_with_lines}, " \
"coverage: #{res.coverage_f * 100}%\n" +
res.pretty_print
end
end

def success
"#{Rainbow('undercover').bold.green}: ✅ No coverage" \
' is missing in latest changes'
"#{Rainbow('undercover').bold.green}: ✅ No coverage " \
'is missing in latest changes'
end

def warnings_header
"#{Rainbow('undercover').bold.red}: " \
'👮‍♂️ some methods have no test coverage! Please add specs for' \
' methods listed below'
'👮‍♂️ some methods have no test coverage! Please add specs for ' \
'methods listed below'
end

def pad_size
Expand Down
10 changes: 5 additions & 5 deletions lib/undercover/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def coverage_f
lines[ln] = 0
end
end
return 1.0 if lines.keys.size.zero?
return 1.0 if lines.keys.empty?

(lines.values.sum.to_f / lines.keys.size).round(4)
end
Expand Down Expand Up @@ -84,7 +84,7 @@ def pretty_print
pad = node.last_line.to_s.length
pretty_print_lines.map do |covered, (num, line)|
formatted_line = "#{num.to_s.rjust(pad)}: #{line}"
if line.strip.length.zero?
if line.strip.empty?
Rainbow(formatted_line).darkgray.dark
elsif covered.nil?
Rainbow(formatted_line).darkgray.dark + \
Expand All @@ -107,8 +107,8 @@ def file_path_with_lines
end

def inspect
"#<Undercover::Report::Result:#{object_id}" \
" name: #{node.name}, coverage: #{coverage_f}>"
"#<Undercover::Report::Result:#{object_id} " \
"name: #{node.name}, coverage: #{coverage_f}>"
end
alias to_s inspect

Expand All @@ -119,7 +119,7 @@ def count_covered_branches(line_number)
branches = coverage.select { |cov| cov.size == 4 && cov[0] == line_number }
count_covered = branches.count { |cov| cov[3].positive? }

return '' if branches.size.zero?
return '' if branches.empty?

if count_covered < branches.size
Rainbow(' branches: ').italic.darkgray.dark + \
Expand Down
28 changes: 28 additions & 0 deletions spec/changeset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,32 @@
changeset = Undercover::Changeset.new('spec/fixtures/test.git', 'master')
expect(changeset.last_modified).to eq(Undercover::Changeset::T_ZERO)
end

describe 'validate' do
let(:report_path) { 'spec/fixtures/sample.lcov' }

it 'returns :no_changes with empty files' do
changeset = Undercover::Changeset.new('spec/fixtures/test.git', 'master') # no update
expect(changeset.validate(report_path)).to eq(:no_changes)
end

it 'returns :stale_coverage if coverage report is older than last file change' do
changeset = Undercover::Changeset.new('spec/fixtures/test.git', 'master').update

Timecop.freeze do
file_paths = changeset.file_paths.map { |p| "spec/fixtures/#{p}" }
FileUtils.touch(file_paths, mtime: Time.now)
FileUtils.touch(report_path, mtime: Time.now - 60)
end

expect(changeset.validate(report_path)).to eq(:stale_coverage)
end

it 'returns nil with no validation errors' do
changeset = Undercover::Changeset.new('spec/fixtures/test.git', 'master').update
FileUtils.touch(report_path, mtime: Time.now)

expect(changeset.validate(report_path)).to be_nil
end
end
end
7 changes: 7 additions & 0 deletions spec/result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@
expect(result.coverage_f).to eq(0.0)
end

it 'has a fiendly #inspect' do
node = ast.find_all(with_name('foo')).first
result = described_class.new(node, coverage, 'class.rb')

expect(result.to_s).to match(/#<Undercover::Report::Result:\d+ name: foo, coverage: 0.0/)
end

context 'for an empty module def' do
let(:ast) { Imagen.from_local('spec/fixtures/empty_class_def.rb') }
let(:lcov) do
Expand Down
21 changes: 5 additions & 16 deletions undercover.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'undercover/version'

# rubocop:disable Metrics/BlockLength
Gem::Specification.new do |spec|
spec.name = 'undercover'
spec.version = Undercover::VERSION
spec.authors = ['Jan Grodowski']
spec.email = ['[email protected]']

spec.summary = 'Actionable code coverage - detects untested' \
' code blocks in recent changes'
spec.summary = 'Actionable code coverage - detects untested ' \
'code blocks in recent changes'
spec.homepage = 'https://github.com/grodowski/undercover'
spec.license = 'MIT'
spec.metadata = {
Expand All @@ -26,20 +25,10 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.required_ruby_version = '>= 2.7.0'
spec.required_ruby_version = '>= 3.0.0'

spec.add_dependency 'bigdecimal'
spec.add_dependency 'imagen', '>= 0.1.8'
spec.add_dependency 'rainbow', '>= 2.1', '< 4.0'
spec.add_dependency 'rugged', '>= 0.27', '< 1.7'

spec.add_development_dependency 'bundler'
spec.add_development_dependency 'pry'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'rubocop', '~> 1.28.2'
spec.add_development_dependency 'simplecov'
spec.add_development_dependency 'simplecov-html'
spec.add_development_dependency 'simplecov-lcov', '~> 0.8'
spec.add_development_dependency 'timecop'
spec.add_dependency 'rugged', '>= 0.27', '< 1.8'
end
# rubocop:enable Metrics/BlockLength

0 comments on commit 1f6df58

Please sign in to comment.