Skip to content

Commit

Permalink
Fix tests after refactor Yabeda::Metric#adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
Keallar committed Oct 1, 2024
1 parent c0ce489 commit daed6fb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 29 deletions.
45 changes: 45 additions & 0 deletions spec/yabeda/metric_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 0 additions & 29 deletions spec/yabeda_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit daed6fb

Please sign in to comment.