Skip to content

Commit

Permalink
Improve specs based on undercover
Browse files Browse the repository at this point in the history
  • Loading branch information
grodowski committed Jan 8, 2024
1 parent 52b8277 commit 2f9ff01
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/undercover/changeset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ 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?

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 eq('#<Undercover::Report::Result:8300 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

0 comments on commit 2f9ff01

Please sign in to comment.