debian-mirror-gitlab/spec/support/gitlab/usage/metrics_instrumentation_shared_examples.rb

39 lines
1.1 KiB
Ruby
Raw Normal View History

2021-06-08 01:23:25 +05:30
# frozen_string_literal: true
2021-09-04 01:27:46 +05:30
RSpec.shared_examples 'a correct instrumented metric value' do |params|
let(:time_frame) { params[:time_frame] }
let(:options) { params[:options] }
let(:metric) { described_class.new(time_frame: time_frame, options: options) }
2021-06-08 01:23:25 +05:30
before do
allow(ActiveRecord::Base.connection).to receive(:transaction_open?).and_return(false)
end
it 'has correct value' do
2021-09-04 01:27:46 +05:30
expect(metric.value).to eq(expected_value)
2021-06-08 01:23:25 +05:30
end
end
2021-09-04 01:27:46 +05:30
RSpec.shared_examples 'a correct instrumented metric query' do |params|
let(:time_frame) { params[:time_frame] }
let(:options) { params[:options] }
let(:metric) { described_class.new(time_frame: time_frame, options: options) }
around do |example|
freeze_time { example.run }
end
before do
allow(ActiveRecord::Base.connection).to receive(:transaction_open?).and_return(false)
end
it 'has correct generate query' do
expect(metric.to_sql).to eq(expected_query)
end
end
RSpec.shared_examples 'a correct instrumented metric value and query' do |params|
it_behaves_like 'a correct instrumented metric value', params
it_behaves_like 'a correct instrumented metric query', params
end