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

Config for min-coverage #21

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Once installed, `pronto run` will include undercover warnings. You can verify th

`pronto-undercover` stores options passed to undercover in `.pronto.yml`. Please note that `--git-dir` and `--compare` options are not available, because `pronto-undercover` uses `Pronto::Git` instead of undercover's implementation.

`min-coverage`: Minimum coverage for `coverage:`, not raise warning if more than it.

Available options:

```
Expand All @@ -33,6 +35,7 @@ pronto-undercover:
path: path/to/project
lcov: path/to/project/coverage/report.lcov
ruby-syntax: ruby19
min-coverage: 1
```

## License
Expand Down
10 changes: 10 additions & 0 deletions lib/pronto/undercover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def patch_to_undercover_message(patch)
.added_lines
.select { |line| line.new_lineno == msg_line_no }
.map do |line|
# binding.pry
next if warning.coverage_f >= min_coverage

lines = untested_lines_for(warning)
path = line.patch.delta.new_file[:path]
msg = "#{warning.node.human_name} #{warning.node.name} missing tests" \
Expand Down Expand Up @@ -85,5 +88,12 @@ def undercover_options
opts << "-p#{config['path']}" if config['path']
::Undercover::Options.new.parse(opts)
end

def min_coverage
@min_coverage ||= ENV['PRONTO_UNDERCOVER_MIN_COVERAGE'] ||
Pronto::ConfigFile.new.to_h.dig('pronto-undercover',
'min-coverage') ||
1
end
end
end
1 change: 1 addition & 0 deletions pronto-undercover.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'simplecov-html'
spec.add_development_dependency 'simplecov-lcov'
spec.add_development_dependency 'timecop'
spec.metadata['rubygems_mfa_required'] = 'true'
end
13 changes: 9 additions & 4 deletions spec/pronto/undercover_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
{
'lcov' => 'coverage/lcov/fixtures.lcov',
'path' => '.',
'ruby-syntax' => 'ruby22'
'ruby-syntax' => 'ruby22',
'min-coverage' => 1
}
end
subject { Pronto::Undercover.new(patches) }
Expand Down Expand Up @@ -47,6 +48,12 @@
expect(msg.runner).to eq(Pronto::Undercover)
end

it 'not report if coverage >= min_coverage' do
write_config('min-coverage' => 0.5)
results = Pronto.run(:staged, 'test.git', nil)
expect(results.size).to eq(1)
end

it 'passes options from .pronto.yml to Undercover::Report' do
write_config(valid_config)

Expand Down Expand Up @@ -95,9 +102,7 @@
end

def write_config(yaml_config_hash)
File.open('.pronto.yml', 'w') do |config_file|
config_file.write({'pronto-undercover' => yaml_config_hash}.to_yaml)
end
File.write('.pronto.yml', {'pronto-undercover' => yaml_config_hash}.to_yaml)
end

def delete_config
Expand Down