|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +require 'datadog/core/deprecations' |
| 4 | + |
| 5 | +RSpec.describe Datadog::Core::Deprecations do |
| 6 | + context 'when extended' do |
| 7 | + subject(:test_class) { Class.new { extend Datadog::Core::Deprecations } } |
| 8 | + |
| 9 | + describe '.log_deprecation' do |
| 10 | + subject(:log_deprecation) { call_log_deprecation } |
| 11 | + |
| 12 | + let(:options) { {} } |
| 13 | + let(:message) { 'Longer allowed.' } |
| 14 | + |
| 15 | + def call_log_deprecation |
| 16 | + test_class.log_deprecation(**options) { message } |
| 17 | + end |
| 18 | + |
| 19 | + context 'by default' do |
| 20 | + it 'warns with enforcement message' do |
| 21 | + expect(Datadog.logger).to receive(:warn) do |&block| |
| 22 | + expect(block.call).to eq('Longer allowed. This will be enforced in the next major release.') |
| 23 | + end |
| 24 | + log_deprecation |
| 25 | + end |
| 26 | + |
| 27 | + it 'does not limit messages' do |
| 28 | + expect(Datadog.logger).to receive(:warn).twice |
| 29 | + 2.times { call_log_deprecation } |
| 30 | + end |
| 31 | + end |
| 32 | + |
| 33 | + context 'with disallowed_next_major:' do |
| 34 | + let(:options) { { disallowed_next_major: disallowed_next_major } } |
| 35 | + |
| 36 | + context 'true' do |
| 37 | + let(:disallowed_next_major) { true } |
| 38 | + |
| 39 | + it 'warns with enforcement message' do |
| 40 | + expect(Datadog.logger).to receive(:warn) do |&block| |
| 41 | + expect(block.call).to eq('Longer allowed. This will be enforced in the next major release.') |
| 42 | + end |
| 43 | + log_deprecation |
| 44 | + end |
| 45 | + end |
| 46 | + |
| 47 | + context 'false' do |
| 48 | + let(:disallowed_next_major) { false } |
| 49 | + |
| 50 | + it 'warns with enforcement message' do |
| 51 | + expect(Datadog.logger).to receive(:warn) do |&block| |
| 52 | + expect(block.call).to eq('Longer allowed.') |
| 53 | + end |
| 54 | + log_deprecation |
| 55 | + end |
| 56 | + end |
| 57 | + end |
| 58 | + |
| 59 | + context 'with key:' do |
| 60 | + let(:options) { { key: key } } |
| 61 | + |
| 62 | + context 'nil' do |
| 63 | + let(:key) { nil } |
| 64 | + |
| 65 | + it 'does not limit messages' do |
| 66 | + expect(Datadog.logger).to receive(:warn).twice |
| 67 | + 2.times { call_log_deprecation } |
| 68 | + end |
| 69 | + end |
| 70 | + |
| 71 | + context 'Symbol' do |
| 72 | + let(:key) { :deprecated_setting } |
| 73 | + |
| 74 | + it 'limits messages' do |
| 75 | + expect(Datadog.logger).to receive(:warn).once |
| 76 | + 2.times { call_log_deprecation } |
| 77 | + end |
| 78 | + end |
| 79 | + |
| 80 | + context 'String' do |
| 81 | + let(:key) { 'deprecated_setting' } |
| 82 | + |
| 83 | + it 'limits messages' do |
| 84 | + expect(Datadog.logger).to receive(:warn).once |
| 85 | + 2.times { call_log_deprecation } |
| 86 | + end |
| 87 | + end |
| 88 | + end |
| 89 | + end |
| 90 | + end |
| 91 | +end |
0 commit comments