File: branch_spec.rb

package info (click to toggle)
ruby-simplecov 0.22.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,512 kB
  • sloc: ruby: 5,550; makefile: 10
file content (105 lines) | stat: -rw-r--r-- 2,948 bytes parent folder | download | duplicates (4)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# frozen_string_literal: true

require "helper"

describe SimpleCov::SourceFile::Branch do
  let(:if_branch) do
    described_class.new(start_line: 1, end_line: 3, coverage: 0, inline: false, type: :then)
  end

  let(:else_branch) do
    described_class.new(start_line: 1, end_line: 3, coverage: 0, inline: false, type: :else)
  end

  context "a source branch if..else" do
    it "correct branch report" do
      expect(if_branch.report).to eq([:then, 0])
      expect(else_branch.report).to eq([:else, 0])
    end
  end

  context "A source branch with coverage" do
    let(:covered_branch) do
      described_class.new(start_line: 1, end_line: 3, coverage: 1, inline: false, type: :then)
    end

    it "is covered" do
      expect(covered_branch).to be_covered
    end

    it "is neither covered not missed if skipped" do
      covered_branch.skipped!
      expect(covered_branch).not_to be_covered
      expect(covered_branch).not_to be_missed
    end

    it "is not missed" do
      expect(covered_branch).not_to be_missed
    end
  end

  context "a source branch without coverage" do
    let(:uncovered_branch) do
      described_class.new(start_line: 1, end_line: 3, coverage: 0, inline: false, type: :then)
    end

    it "isn't covered" do
      expect(uncovered_branch).not_to be_covered
    end

    it "is missed" do
      expect(uncovered_branch).to be_missed
    end

    it "is neither covered not missed if skipped" do
      uncovered_branch.skipped!
      expect(uncovered_branch).not_to be_covered
      expect(uncovered_branch).not_to be_missed
    end
  end

  describe "skipping lines" do
    subject { described_class.new(start_line: 5, end_line: 7, coverage: 0, inline: false, type: :then) }

    it "isn't skipped by default" do
      expect(subject).not_to be_skipped
    end

    it "can be skipped" do
      subject.skipped!
      expect(subject).to be_skipped
    end
  end

  describe "#overlaps_with?(range)" do
    subject { described_class.new(start_line: 5, end_line: 7, coverage: 0, inline: false, type: :then) }

    it "doesn't overlap with a range beyond its lines" do
      expect(subject.overlaps_with?(8..10)).to eq false
    end

    it "doesn't overlap with a range before its lines" do
      expect(subject.overlaps_with?(3..4)).to eq false
    end

    it "overlaps with a range that fully includes everything" do
      expect(subject.overlaps_with?(1..100)).to eq true
    end

    it "overlaps with a range that exactly includes it" do
      expect(subject.overlaps_with?(5..7)).to eq true
    end

    it "overlaps with a range that partially includes its beginning" do
      expect(subject.overlaps_with?(1..5)).to eq true
    end

    it "overlaps with a range that partially includes its end" do
      expect(subject.overlaps_with?(7..10)).to eq true
    end

    it "overlaps with a range that pends in its middle" do
      expect(subject.overlaps_with?(1..6)).to eq true
    end
  end
end