File: base_distributor_spec.rb

package info (click to toggle)
ruby-knapsack 1.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,084 kB
  • sloc: ruby: 2,832; makefile: 4; sh: 3
file content (88 lines) | stat: -rw-r--r-- 2,447 bytes parent folder | download
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
describe Knapsack::Distributors::BaseDistributor do
  let(:report) { { 'a_spec.rb' => 1.0 } }
  let(:default_args) do
    {
      report: report,
      test_file_pattern: 'spec/**{,/*/**}/*_spec.rb',
      ci_node_total: '1',
      ci_node_index: '0'
    }
  end
  let(:args) { default_args.merge(custom_args) }
  let(:custom_args) { {} }
  let(:distributor) { described_class.new(args) }

  describe '#report' do
    subject { distributor.report }

    context 'when report is given' do
      it { should eql(report) }
    end

    context 'when report is not given' do
      let(:custom_args) { { report: nil } }
      it { expect { subject }.to raise_error('Missing report') }
    end
  end

  describe '#ci_node_total' do
    subject { distributor.ci_node_total }

    context 'when ci_node_total is given' do
      it { should eql 1 }
    end

    context 'when ci_node_total is not given' do
      let(:custom_args) { { ci_node_total: nil } }
      it { expect { subject }.to raise_error('Missing ci_node_total') }
    end
  end

  describe '#ci_node_index' do
    subject { distributor.ci_node_index }

    context 'when ci_node_index is given' do
      it { should eql 0 }
    end

    context 'when ci_node_index is not given' do
      let(:custom_args) { { ci_node_index: nil } }
      it { expect { subject }.to raise_error('Missing ci_node_index') }
    end

    context 'when ci_node_index has not allowed value' do
      let(:expected_exception_message) do
        "Node indexes are 0-based. Can't be higher or equal to the total number of nodes."
      end

      context 'when ci_node_index is equal to ci_node_total' do
        let(:custom_args) { { ci_node_index: 1, ci_node_total: 1 } }
        it { expect { subject }.to raise_error(expected_exception_message) }
      end

      context 'when ci_node_index is higher than ci_node_total' do
        let(:custom_args) { { ci_node_index: 2, ci_node_total: 1 } }
        it { expect { subject }.to raise_error(expected_exception_message) }
      end
    end
  end

  describe '#tests_for_current_node' do
    let(:custom_args) do
      {
        ci_node_total: 3,
        ci_node_index: ci_node_index
      }
    end
    let(:ci_node_index) { 2 }
    let(:tests) { double }

    subject { distributor.tests_for_current_node }

    before do
      expect(distributor).to receive(:tests_for_node).with(ci_node_index).and_return(tests)
    end

    it { should eql tests }
  end
end