Commit cbf279f9 authored by Piotr Skorupa's avatar Piotr Skorupa

Add specs for UsageMetricDefinitionGenerator

parent 6a072b26
# frozen_string_literal: true
require 'spec_helper'
RSpec.configure do |config|
# Redirect stdout so specs don't have so much noise
config.before(:all) do
$stdout = StringIO.new
end
# Reset stdout
config.after(:all) do
$stdout = STDOUT
end
end
# frozen_string_literal: true
require 'generator_helper'
RSpec.describe Gitlab::UsageMetricDefinitionGenerator do
describe 'Running generator' do
let(:key_path) { 'counter.category.event' }
let(:dir) { '7d' }
let(:options) { [key_path, '--dir', dir, '--pretend'] }
subject { described_class.start(options) }
it 'does not raise an error' do
expect { subject }.not_to raise_error
end
context 'with a missing directory' do
let(:options) { [key_path, '--pretend'] }
it 'raises an error' do
expect { subject }.to raise_error(RuntimeError)
end
end
context 'with an invalid directory' do
let(:dir) { '8d' }
it 'raises an error' do
expect { subject }.to raise_error(RuntimeError)
end
end
context 'with an already existing metric with the same key_path' do
before do
allow(Gitlab::Usage::MetricDefinition).to receive(:definitions).and_return(Hash[key_path, 'definition'])
end
it 'raises an error' do
expect { subject }.to raise_error(RuntimeError)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment