Skip to content

Commit

Permalink
Add tests for top-level blocks (closes #83, closes #135)
Browse files Browse the repository at this point in the history
  • Loading branch information
grodowski committed Dec 3, 2024
1 parent 18df595 commit 2e0320b
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Add support for including and exluding files by glob patterns, supplied through CLI args and the configuration file (#146)

### Fixed
- Files that were changed but don't appear in the coverage report at all will now be reported as uncovered, as expected.
- Fixed an issue where top-level methods were not being considered (#135). This was caused by a bug in the tree traversal logic.

# [0.5.0] - 2024-01-09
### Changed
Expand Down
4 changes: 2 additions & 2 deletions spec/changeset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
).update

expect(changeset.files.keys).to match_array(
%w[file_one file_two staged_file class.rb module.rb]
%w[file_one file_two staged_file class.rb module.rb sinatra.rb]
)
expect(changeset.files['file_two']).to eq([7, 10, 11])
end
Expand All @@ -24,7 +24,7 @@
).update

expect(changeset.file_paths).to match_array(
%w[file_one file_three file_two staged_file class.rb module.rb]
%w[file_one file_three file_two staged_file class.rb module.rb sinatra.rb]
)
expect(changeset.files['file_two']).to eq([7, 10, 11])
expect(changeset.files['file_three']).to eq([1, 2, 3, 4, 5, 6])
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'

def rakefile # TODO: fix known issue of not parsing top-level expressions!
def rakefile
desc 'Run RuboCop'
RuboCop::RakeTask.new(:rubocop)

Expand Down
4 changes: 4 additions & 0 deletions spec/fixtures/sinatra.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'sinatra'
get '/dummy_path' do
"This line is not covered"
end
Binary file modified spec/fixtures/test.git/index
Binary file not shown.
Binary file not shown.
15 changes: 12 additions & 3 deletions spec/report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
it 'builds a report with coverage metrics' do
report.build

expect(report.results.size).to eq(2)
expect(report.results.size).to eq(3)
all = report.all_results
expect(all[0]).to be_an(Undercover::Result)
expect(all[0].coverage_f).to eq(0.8333)
Expand Down Expand Up @@ -54,6 +54,15 @@
expect(unflagged[0].coverage_f).to eq(0.875)
expect(unflagged[1].name).to eq('baz')
expect(unflagged[1].coverage_f).to eq(1.0)

# includes blocks at top-level (reproduce https://github.com/grodowski/undercover/issues/135)
top_level_results = report.results['sinatra.rb'].to_a
expect(top_level_results.size).to eq(1)
expect(top_level_results[0].name).to eq('block')
expect(top_level_results[0].coverage_f).to eq(0.0)
expect(top_level_results[0].flagged?).to eq(true)
expect(top_level_results[0].first_line).to eq(2)
expect(top_level_results[0].last_line).to eq(4)
end

it 'does not parse files outside of the lcov report' do
Expand All @@ -67,13 +76,13 @@
it 'builds pathnames relative to --path' do
report.build

expect(report.results.keys.sort).to eq(%w[class.rb module.rb])
expect(report.results.keys.sort).to eq(%w[class.rb module.rb sinatra.rb])
end

it 'builds does not mess up with result keys' do
report.build

expect(report.results.keys.sort).to eq(%w[class.rb module.rb])
expect(report.results.keys.sort).to eq(%w[class.rb module.rb sinatra.rb])
end

context 'with mock changeset' do
Expand Down

0 comments on commit 2e0320b

Please sign in to comment.