Welcome to mirror list, hosted at ThFree Co, Russian Federation.

base_rpm_service_shared_examples.rb « services « shared_examples « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c9520852a5bc2ff052bb70bb143e6bdfd329a349 (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
43
44
45
46
47
48
49
50
51
52
# frozen_string_literal: true

RSpec.shared_examples 'handling rpm xml file' do
  include_context 'with rpm package data'

  let(:xml) { nil }
  let(:data) { {} }

  context 'when generate empty xml' do
    it 'generate expected xml' do
      expect(subject).to eq(empty_xml)
    end
  end

  context 'when updating existing xml' do
    let(:xml) { empty_xml }
    let(:data) { xml_update_params }

    shared_examples 'changing root tag attribute' do
      it "increment previous 'packages' value by 1" do
        previous_value = Nokogiri::XML(xml).at(described_class::ROOT_TAG).attributes["packages"].value.to_i
        new_value = Nokogiri::XML(subject).at(described_class::ROOT_TAG).attributes["packages"].value.to_i

        expect(previous_value + 1).to eq(new_value)
      end
    end

    it 'generate valid xml add expected xml node to existing xml' do
      # Have one root attribute
      result = Nokogiri::XML::Document.parse(subject).remove_namespaces!
      expect(result.children.count).to eq(1)

      # Root node has 1 child with generated node
      expect(result.xpath("//#{described_class::ROOT_TAG}/package").count).to eq(1)
    end

    context 'when empty xml' do
      it_behaves_like 'changing root tag attribute'
    end

    context 'when xml has children' do
      let(:xml) { described_class.new(xml: empty_xml, data: data).execute }

      it 'has children nodes' do
        result = Nokogiri::XML::Document.parse(xml).remove_namespaces!
        expect(result.children.count).to be > 0
      end

      it_behaves_like 'changing root tag attribute'
    end
  end
end