summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/lib/gitlab/alert_management/payload.rb
blob: 54b021e837121a8016bf73b230cdb476bfd9ffbd (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
# frozen_string_literal: true

RSpec.shared_examples 'parsable alert payload field with fallback' do |fallback, *paths|
  context 'without payload' do
    it { is_expected.to eq(fallback) }
  end

  paths.each do |path|
    context "with #{path}" do
      let(:value) { 'some value' }

      before do
        section, name = path.split('/')
        raw_payload[section] = name ? { name => value } : value
      end

      it { is_expected.to eq(value) }
    end
  end
end

RSpec.shared_examples 'parsable alert payload field' do |*paths|
  it_behaves_like 'parsable alert payload field with fallback', nil, *paths
end

RSpec.shared_examples 'subclass has expected api' do
  it 'defines all public methods in the base class' do
    default_methods = Gitlab::AlertManagement::Payload::Base.public_instance_methods
    subclass_methods = described_class.public_instance_methods
    missing_methods = subclass_methods - default_methods

    expect(missing_methods).to be_empty
  end
end