|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | describe Hooks::Core::Builder do |
| 4 | + let(:log) { instance_double(Logger).as_null_object } |
4 | 5 | let(:temp_dir) { "/tmp/hooks_builder_test" } |
5 | 6 |
|
6 | 7 | before do |
|
13 | 14 |
|
14 | 15 | describe "#initialize" do |
15 | 16 | it "initializes with no parameters" do |
16 | | - builder = described_class.new |
| 17 | + builder = described_class.new(log:) |
17 | 18 |
|
18 | | - expect(builder.instance_variable_get(:@log)).to be_nil |
| 19 | + expect(builder.instance_variable_get(:@log)).to eq(log) |
19 | 20 | expect(builder.instance_variable_get(:@config_input)).to be_nil |
20 | 21 | end |
21 | 22 |
|
22 | 23 | it "initializes with config parameter" do |
23 | 24 | config = { log_level: "debug" } |
24 | | - builder = described_class.new(config: config) |
| 25 | + builder = described_class.new(config:, log:) |
25 | 26 |
|
26 | 27 | expect(builder.instance_variable_get(:@config_input)).to eq(config) |
27 | 28 | end |
28 | 29 |
|
29 | 30 | it "initializes with custom logger" do |
30 | | - logger = double("Logger") |
31 | | - builder = described_class.new(log: logger) |
32 | | - |
33 | | - expect(builder.instance_variable_get(:@log)).to eq(logger) |
| 31 | + builder = described_class.new(log:) |
| 32 | + expect(builder.instance_variable_get(:@log)).to eq(log) |
34 | 33 | end |
35 | 34 |
|
36 | 35 | it "initializes with both config and logger" do |
37 | 36 | config = { environment: "test" } |
38 | | - logger = double("Logger") |
39 | | - builder = described_class.new(config: config, log: logger) |
| 37 | + builder = described_class.new(config: config, log:) |
40 | 38 |
|
41 | 39 | expect(builder.instance_variable_get(:@config_input)).to eq(config) |
42 | | - expect(builder.instance_variable_get(:@log)).to eq(logger) |
| 40 | + expect(builder.instance_variable_get(:@log)).to eq(log) |
43 | 41 | end |
44 | 42 | end |
45 | 43 |
|
46 | 44 | describe "#build" do |
47 | 45 | context "with minimal configuration" do |
48 | | - let(:builder) { described_class.new } |
| 46 | + let(:builder) { described_class.new(log:) } |
49 | 47 |
|
50 | 48 | before do |
51 | 49 | # Mock dependencies to prevent actual file system operations |
|
109 | 107 |
|
110 | 108 | context "with custom configuration" do |
111 | 109 | let(:config) { { log_level: "debug", environment: "development" } } |
112 | | - let(:builder) { described_class.new(config: config) } |
| 110 | + let(:builder) { described_class.new(config:, log:) } |
113 | 111 |
|
114 | 112 | before do |
115 | 113 | allow(Hooks::Core::ConfigLoader).to receive(:load).and_return(config) |
|
161 | 159 | { path: "/webhook/test2", handler: "Handler2" } |
162 | 160 | ] |
163 | 161 | end |
164 | | - let(:builder) { described_class.new } |
| 162 | + let(:builder) { described_class.new(log:) } |
165 | 163 |
|
166 | 164 | before do |
167 | 165 | allow(Hooks::Core::ConfigLoader).to receive(:load).and_return({ |
|
250 | 248 | end |
251 | 249 |
|
252 | 250 | context "error handling" do |
253 | | - let(:builder) { described_class.new } |
| 251 | + let(:builder) { described_class.new(log:) } |
254 | 252 |
|
255 | 253 | it "raises ConfigurationError when global config validation fails" do |
256 | 254 | allow(Hooks::Core::ConfigLoader).to receive(:load).and_return({}) |
|
279 | 277 | end |
280 | 278 |
|
281 | 279 | describe "#load_and_validate_config" do |
282 | | - let(:builder) { described_class.new } |
| 280 | + let(:builder) { described_class.new(log:) } |
283 | 281 |
|
284 | 282 | it "is a private method" do |
285 | 283 | expect(described_class.private_instance_methods).to include(:load_and_validate_config) |
286 | 284 | end |
287 | 285 | end |
288 | 286 |
|
289 | 287 | describe "#load_endpoints" do |
290 | | - let(:builder) { described_class.new } |
| 288 | + let(:builder) { described_class.new(log:) } |
291 | 289 |
|
292 | 290 | it "is a private method" do |
293 | 291 | expect(described_class.private_instance_methods).to include(:load_endpoints) |
294 | 292 | end |
295 | 293 | end |
296 | 294 |
|
| 295 | + describe "#load_endpoints" do |
| 296 | + describe "with its own log" do |
| 297 | + let(:builder) { described_class.new } |
| 298 | + |
| 299 | + it "is a private method" do |
| 300 | + expect(described_class.private_instance_methods).to include(:load_endpoints) |
| 301 | + end |
| 302 | + end |
| 303 | + end |
| 304 | + |
297 | 305 | describe "ConfigurationError" do |
298 | 306 | it "is a StandardError" do |
299 | 307 | expect(Hooks::Core::ConfigurationError.new).to be_a(StandardError) |
|
0 commit comments