|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +# Released under the MIT License. |
| 4 | +# Copyright, 2026, by Samuel Williams. |
| 5 | + |
| 6 | +require "falcon/command/host" |
| 7 | +require "sus/fixtures/console/captured_logger" |
| 8 | + |
| 9 | +describe Falcon::Command::Host do |
| 10 | + include Sus::Fixtures::Console::CapturedLogger |
| 11 | + |
| 12 | + let(:command) do |
| 13 | + subject[] |
| 14 | + end |
| 15 | + |
| 16 | + it "runs the controller" do |
| 17 | + captured_configuration = nil |
| 18 | + captured_container_class = nil |
| 19 | + |
| 20 | + mock(Async::Service::Controller) do |controller| |
| 21 | + controller.replace(:run) do |configuration, container_class:| |
| 22 | + captured_configuration = configuration |
| 23 | + captured_container_class = container_class |
| 24 | + end |
| 25 | + end |
| 26 | + |
| 27 | + command.call |
| 28 | + |
| 29 | + expect(captured_configuration).to be_a(Async::Service::Configuration) |
| 30 | + expect(captured_container_class).to be == command.container_class |
| 31 | + |
| 32 | + expect_console.to have_logged( |
| 33 | + severity: be == :info, |
| 34 | + subject: be == command, |
| 35 | + message: be(:include?, "Falcon Host v"), |
| 36 | + ) |
| 37 | + end |
| 38 | + |
| 39 | + it "reports errors from the host entry point" do |
| 40 | + error = RuntimeError.new("boom") |
| 41 | + captured_status = nil |
| 42 | + |
| 43 | + mock(Async::Service::Controller) do |controller| |
| 44 | + controller.replace(:run) do |configuration, container_class:| |
| 45 | + raise error |
| 46 | + end |
| 47 | + end |
| 48 | + |
| 49 | + mock(subject) do |host| |
| 50 | + host.replace(:exit!) do |status| |
| 51 | + captured_status = status |
| 52 | + end |
| 53 | + end |
| 54 | + |
| 55 | + subject.call(["missing.rb"]) |
| 56 | + |
| 57 | + expect(captured_status).to be == 1 |
| 58 | + |
| 59 | + expect_console.to have_logged( |
| 60 | + severity: be == :error, |
| 61 | + subject: be == subject, |
| 62 | + arguments: be == [error], |
| 63 | + message: be == "boom", |
| 64 | + ) |
| 65 | + end |
| 66 | +end |
0 commit comments