|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | require_relative "spec_helper" |
| 4 | + |
| 5 | +describe Hooks do |
| 6 | + describe ".build" do |
| 7 | + context "with default parameters" do |
| 8 | + it "creates a builder and builds the application" do |
| 9 | + allow(Hooks::Core::Builder).to receive(:new).and_call_original |
| 10 | + allow_any_instance_of(Hooks::Core::Builder).to receive(:build).and_return("mock_app") |
| 11 | + |
| 12 | + result = Hooks.build |
| 13 | + |
| 14 | + expect(Hooks::Core::Builder).to have_received(:new).with(config: nil, log: nil) |
| 15 | + expect(result).to eq("mock_app") |
| 16 | + end |
| 17 | + end |
| 18 | + |
| 19 | + context "with custom config" do |
| 20 | + it "passes config to builder" do |
| 21 | + config_hash = { log_level: "debug" } |
| 22 | + allow(Hooks::Core::Builder).to receive(:new).and_call_original |
| 23 | + allow_any_instance_of(Hooks::Core::Builder).to receive(:build).and_return("mock_app") |
| 24 | + |
| 25 | + result = Hooks.build(config: config_hash) |
| 26 | + |
| 27 | + expect(Hooks::Core::Builder).to have_received(:new).with(config: config_hash, log: nil) |
| 28 | + expect(result).to eq("mock_app") |
| 29 | + end |
| 30 | + end |
| 31 | + |
| 32 | + context "with custom logger" do |
| 33 | + it "passes logger to builder" do |
| 34 | + custom_logger = double("Logger") |
| 35 | + allow(Hooks::Core::Builder).to receive(:new).and_call_original |
| 36 | + allow_any_instance_of(Hooks::Core::Builder).to receive(:build).and_return("mock_app") |
| 37 | + |
| 38 | + result = Hooks.build(log: custom_logger) |
| 39 | + |
| 40 | + expect(Hooks::Core::Builder).to have_received(:new).with(config: nil, log: custom_logger) |
| 41 | + expect(result).to eq("mock_app") |
| 42 | + end |
| 43 | + end |
| 44 | + |
| 45 | + context "with both config and logger" do |
| 46 | + it "passes both to builder" do |
| 47 | + config_hash = { environment: "test" } |
| 48 | + custom_logger = double("Logger") |
| 49 | + allow(Hooks::Core::Builder).to receive(:new).and_call_original |
| 50 | + allow_any_instance_of(Hooks::Core::Builder).to receive(:build).and_return("mock_app") |
| 51 | + |
| 52 | + result = Hooks.build(config: config_hash, log: custom_logger) |
| 53 | + |
| 54 | + expect(Hooks::Core::Builder).to have_received(:new).with(config: config_hash, log: custom_logger) |
| 55 | + expect(result).to eq("mock_app") |
| 56 | + end |
| 57 | + end |
| 58 | + end |
| 59 | +end |
0 commit comments