summaryrefslogtreecommitdiff
path: root/spec/tooling/lib/tooling/crystalball/coverage_lines_execution_detector_spec.rb
blob: 6b7373cb3c72c1f3ec801ec3746568e52858caac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# frozen_string_literal: true

require_relative '../../../../../tooling/lib/tooling/crystalball/coverage_lines_execution_detector'

RSpec.describe Tooling::Crystalball::CoverageLinesExecutionDetector do
  subject(:detector) { described_class.new(root, exclude_prefixes: %w[vendor/ruby]) }

  let(:root) { '/tmp' }
  let(:before_map) { { path => { lines: [0, 2, nil] } } }
  let(:after_map) { { path => { lines: [0, 3, nil] } } }
  let(:path) { '/tmp/file.rb' }

  describe '#detect' do
    subject { detector.detect(before_map, after_map) }

    it { is_expected.to eq(%w[file.rb]) }

    context 'with no changes' do
      let(:after_map) { { path => { lines: [0, 2, nil] } } }

      it { is_expected.to eq([]) }
    end

    context 'with previously uncovered file' do
      let(:before_map) { {} }

      it { is_expected.to eq(%w[file.rb]) }
    end

    context 'with path outside of root' do
      let(:path) { '/abc/file.rb' }

      it { is_expected.to eq([]) }
    end

    context 'with path in excluded prefix' do
      let(:path) { '/tmp/vendor/ruby/dependency.rb' }

      it { is_expected.to eq([]) }
    end
  end
end