diff --git a/spec/yabeda/metric_spec.rb b/spec/yabeda/metric_spec.rb index 1599acd..d23534d 100644 --- a/spec/yabeda/metric_spec.rb +++ b/spec/yabeda/metric_spec.rb @@ -61,4 +61,49 @@ it { is_expected.to match_array(%i[foo bar baz]) } end end + + describe "#adapters" do + subject(:metric_adapters) { metric.adapters } + + let(:adapter_name) { :test_adapter } + let(:adapter) { instance_double(Yabeda::BaseAdapter, register!: true) } + let(:another_adapter_name) { :another_test_adapter } + let(:another_adapter) { instance_double(Yabeda::BaseAdapter, register!: true) } + + before do + Yabeda.register_adapter(adapter_name, adapter) + Yabeda.register_adapter(another_adapter_name, another_adapter) + end + + it "returns all adapters" do + aggregate_failures do + expect(metric_adapters).to eq({ + adapter_name => adapter, + another_adapter_name => another_adapter, + }) + expect(metric_adapters.size).to eq(2) + end + end + + context "when metric has option adapter" do + let(:options) { { tags: %i[foo bar], adapter: :test_adapter } } + + it "returns only defined in option adapter" do + aggregate_failures do + expect(metric_adapters).to eq({ + adapter_name => adapter, + }) + expect(metric_adapters.size).to eq(1) + end + end + + context "when adapter option is invalid" do + let(:options) { { tags: %i[foo bar], adapter: :invalid } } + + it "raises error" do + expect { metric_adapters }.to raise_error(Yabeda::ConfigurationError, /invalid adapter option/) + end + end + end + end end diff --git a/spec/yabeda_spec.rb b/spec/yabeda_spec.rb index 735f9e6..9464ab7 100644 --- a/spec/yabeda_spec.rb +++ b/spec/yabeda_spec.rb @@ -134,34 +134,5 @@ expect(adapter).to have_received(:register!).with(described_class.test) end - - context "when not configured" do - before do - described_class.reset! - described_class.configure { histogram :test, buckets: [42], adapter: :invalid } - end - - it "does not register metric for adapter" do - register_adapter - - expect(adapter).not_to have_received(:register!) - end - end - - context "when added another adapter" do - let(:another_adapter_name) { :another_test_adapter } - let(:another_adapter) { instance_double(Yabeda::BaseAdapter, register!: true) } - - before do - described_class.register_adapter(another_adapter_name, another_adapter) - end - - it "changes available adapters in registered metric" do - aggregate_failures do - expect { register_adapter }.to change(described_class.test.adapters, :size).by(1) - expect(another_adapter).to have_received(:register!) - end - end - end end end