-
Notifications
You must be signed in to change notification settings - Fork 148
/
Copy pathmetric_example.rb
53 lines (45 loc) · 1.44 KB
/
metric_example.rb
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
# encoding: UTF-8
shared_examples_for Prometheus::Client::Metric do
subject { described_class.new(:foo, docstring: 'foo description') }
describe '.new' do
it 'returns a new metric' do
expect(subject).to be_a(Prometheus::Client::Metric)
end
it 'raises an exception if a reserved base label is used' do
exception = Prometheus::Client::LabelSetValidator::ReservedLabelError
expect do
described_class.new(:foo,
docstring: 'foo docstring',
preset_labels: { __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, docstring: 'foo')
end.to raise_exception ArgumentError
end
it 'raises an exception if docstring is missing' do
expect do
described_class.new(:foo, docstring: '')
end.to raise_exception ArgumentError
end
it 'raises an exception if a metric name is invalid' do
[
'string',
'42startsWithNumber'.to_sym,
'abc def'.to_sym,
'abcdef '.to_sym,
"abc\ndef".to_sym,
].each do |name|
expect do
described_class.new(name, docstring: 'foo')
end.to raise_exception(ArgumentError)
end
end
end
describe '#type' do
it 'returns the metric type as symbol' do
expect(subject.type).to be_a(Symbol)
end
end
end