Skip to content

Commit 9d13b50

Browse files
committed
cleanup log output
1 parent a8a1960 commit 9d13b50

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

spec/unit/lib/hooks/core/builder_spec.rb

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
describe Hooks::Core::Builder do
4+
let(:log) { instance_double(Logger).as_null_object }
45
let(:temp_dir) { "/tmp/hooks_builder_test" }
56

67
before do
@@ -13,39 +14,36 @@
1314

1415
describe "#initialize" do
1516
it "initializes with no parameters" do
16-
builder = described_class.new
17+
builder = described_class.new(log:)
1718

18-
expect(builder.instance_variable_get(:@log)).to be_nil
19+
expect(builder.instance_variable_get(:@log)).to eq(log)
1920
expect(builder.instance_variable_get(:@config_input)).to be_nil
2021
end
2122

2223
it "initializes with config parameter" do
2324
config = { log_level: "debug" }
24-
builder = described_class.new(config: config)
25+
builder = described_class.new(config:, log:)
2526

2627
expect(builder.instance_variable_get(:@config_input)).to eq(config)
2728
end
2829

2930
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)
3433
end
3534

3635
it "initializes with both config and logger" do
3736
config = { environment: "test" }
38-
logger = double("Logger")
39-
builder = described_class.new(config: config, log: logger)
37+
builder = described_class.new(config: config, log:)
4038

4139
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)
4341
end
4442
end
4543

4644
describe "#build" do
4745
context "with minimal configuration" do
48-
let(:builder) { described_class.new }
46+
let(:builder) { described_class.new(log:) }
4947

5048
before do
5149
# Mock dependencies to prevent actual file system operations
@@ -109,7 +107,7 @@
109107

110108
context "with custom configuration" do
111109
let(:config) { { log_level: "debug", environment: "development" } }
112-
let(:builder) { described_class.new(config: config) }
110+
let(:builder) { described_class.new(config:, log:) }
113111

114112
before do
115113
allow(Hooks::Core::ConfigLoader).to receive(:load).and_return(config)
@@ -161,7 +159,7 @@
161159
{ path: "/webhook/test2", handler: "Handler2" }
162160
]
163161
end
164-
let(:builder) { described_class.new }
162+
let(:builder) { described_class.new(log:) }
165163

166164
before do
167165
allow(Hooks::Core::ConfigLoader).to receive(:load).and_return({
@@ -250,7 +248,7 @@
250248
end
251249

252250
context "error handling" do
253-
let(:builder) { described_class.new }
251+
let(:builder) { described_class.new(log:) }
254252

255253
it "raises ConfigurationError when global config validation fails" do
256254
allow(Hooks::Core::ConfigLoader).to receive(:load).and_return({})
@@ -279,21 +277,31 @@
279277
end
280278

281279
describe "#load_and_validate_config" do
282-
let(:builder) { described_class.new }
280+
let(:builder) { described_class.new(log:) }
283281

284282
it "is a private method" do
285283
expect(described_class.private_instance_methods).to include(:load_and_validate_config)
286284
end
287285
end
288286

289287
describe "#load_endpoints" do
290-
let(:builder) { described_class.new }
288+
let(:builder) { described_class.new(log:) }
291289

292290
it "is a private method" do
293291
expect(described_class.private_instance_methods).to include(:load_endpoints)
294292
end
295293
end
296294

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+
297305
describe "ConfigurationError" do
298306
it "is a StandardError" do
299307
expect(Hooks::Core::ConfigurationError.new).to be_a(StandardError)

0 commit comments

Comments
 (0)