File: allocator_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 (68 lines) | stat: -rw-r--r-- 2,150 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
describe Knapsack::Allocator do
  let(:test_file_pattern) { nil }
  let(:args) do
    {
      ci_node_total: nil,
      ci_node_index: nil,
      test_file_pattern: test_file_pattern,
      report: nil
    }
  end
  let(:report_distributor) { instance_double(Knapsack::Distributors::ReportDistributor) }
  let(:leftover_distributor) { instance_double(Knapsack::Distributors::LeftoverDistributor) }
  let(:report_tests) { ['a_spec.rb', 'b_spec.rb'] }
  let(:leftover_tests) { ['c_spec.rb', 'd_spec.rb'] }
  let(:node_tests) { report_tests + leftover_tests }
  let(:allocator) { described_class.new(args) }

  before do
    expect(Knapsack::Distributors::ReportDistributor).to receive(:new).with(args).and_return(report_distributor)
    expect(Knapsack::Distributors::LeftoverDistributor).to receive(:new).with(args).and_return(leftover_distributor)
    allow(report_distributor).to receive(:tests_for_current_node).and_return(report_tests)
    allow(leftover_distributor).to receive(:tests_for_current_node).and_return(leftover_tests)
  end

  describe '#report_node_tests' do
    subject { allocator.report_node_tests }
    it { should eql report_tests }
  end

  describe '#leftover_node_tests' do
    subject { allocator.leftover_node_tests }
    it { should eql leftover_tests }
  end

  describe '#node_tests' do
    subject { allocator.node_tests }
    it { should eql node_tests }
  end

  describe '#stringify_node_tests' do
    subject { allocator.stringify_node_tests }
    it { should eql %{"a_spec.rb" "b_spec.rb" "c_spec.rb" "d_spec.rb"} }
  end

  describe '#test_dir' do
    subject { allocator.test_dir }

    context 'when ENV test_dir has value' do
      let(:test_dir) { "custom_dir" }

      before do
        expect(Knapsack::Config::Env).to receive(:test_dir).and_return(test_dir)
      end

      it { should eql 'custom_dir' }
    end

    context 'when ENV test_dir has no value' do
      let(:test_file_pattern) { "test_dir/**{,/*/**}/*_spec.rb" }

      before do
        expect(report_distributor).to receive(:test_file_pattern).and_return(test_file_pattern)
      end

      it { should eql 'test_dir' }
    end
  end
end