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

test_resources_data_processor_spec.rb « tools « spec « qa - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5117d1d367f16d623ab5384c0191ce775c0dd88e (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
53
54
55
56
57
58
59
60
# frozen_string_literal: true

require 'active_support/testing/time_helpers'

RSpec.describe QA::Tools::TestResourceDataProcessor do
  include QA::Support::Helpers::StubEnv
  include ActiveSupport::Testing::TimeHelpers

  subject(:processor) { Class.new(described_class).instance }

  let(:info) { 'information' }
  let(:api_response) { {} }
  let(:method) { :api }
  let(:time) { 2 }
  let(:api_path) { resource.api_delete_path }
  let(:resource) { QA::Resource::Project.init { |project| project.id = 1 } }

  let(:result) do
    {
      'QA::Resource::Project' => [{
        info: info,
        api_path: api_path,
        fabrication_method: method,
        fabrication_time: time,
        http_method: :post,
        timestamp: Time.now.to_s
      }]
    }
  end

  before do
    processor.collect(resource: resource, info: info, fabrication_method: method, fabrication_time: time)
  end

  around do |example|
    freeze_time { example.run }
  end

  describe '.collect' do
    it 'collects and stores resource' do
      expect(processor.resources).to eq(result)
    end
  end

  describe '.write_to_file' do
    let(:resources_file) { Pathname.new(Faker::File.file_name(dir: 'tmp', ext: 'json')) }

    before do
      stub_env('QA_TEST_RESOURCES_CREATED_FILEPATH', resources_file)

      allow(File).to receive(:write)
    end

    it 'writes applicable resources to file' do
      processor.write_to_file

      expect(File).to have_received(:write).with(resources_file, JSON.pretty_generate(result))
    end
  end
end