File: metric_example.rb

package info (click to toggle)
ruby-prometheus-client-mmap 1.2.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 700 kB
  • sloc: ruby: 3,149; sh: 54; makefile: 21
file content (47 lines) | stat: -rw-r--r-- 1,215 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
# encoding: UTF-8

shared_examples_for Prometheus::Client::Metric do
  subject { described_class.new(:foo, 'foo description') }

  describe '.new' do
    it 'returns a new metric' do
      expect(subject).to be
    end

    it 'raises an exception if a reserved base label is used' do
      exception = Prometheus::Client::LabelSetValidator::ReservedLabelError

      expect do
        described_class.new(:foo, 'foo docstring', __name__: 'reserved')
      end.to raise_exception exception
    end

    it 'raises an exception if the given name is blank' do
      expect do
        described_class.new(nil, 'foo')
      end.to raise_exception ArgumentError
    end

    it 'raises an exception if docstring is missing' do
      expect do
        described_class.new(:foo, '')
      end.to raise_exception ArgumentError
    end
  end

  describe '#type' do
    it 'returns the metric type as symbol' do
      expect(subject.type).to be_a(Symbol)
    end
  end

  describe '#get' do
    it 'returns the current metric value' do
      expect(subject.get).to be_a(type)
    end

    it 'returns the current metric value for a given label set' do
      expect(subject.get(test: 'label')).to be_a(type)
    end
  end
end