diff --git a/lib/kangaru/application.rb b/lib/kangaru/application.rb index b13e0f2..d1e0445 100644 --- a/lib/kangaru/application.rb +++ b/lib/kangaru/application.rb @@ -18,6 +18,12 @@ def setup autoloader.setup end + def run!(argv) + command = Command.parse(argv) + + Router.new(command, namespace:).resolve + end + private def autoloader diff --git a/sig/kangaru/application.rbs b/sig/kangaru/application.rbs index 3282811..c57dfc9 100644 --- a/sig/kangaru/application.rbs +++ b/sig/kangaru/application.rbs @@ -12,6 +12,8 @@ module Kangaru def setup: -> void + def run!: (Array[String]) -> void + private attr_reader autoloader: Zeitwerk::Loader diff --git a/spec/kangaru/application_spec.rb b/spec/kangaru/application_spec.rb index 7e050a1..eeca991 100644 --- a/spec/kangaru/application_spec.rb +++ b/spec/kangaru/application_spec.rb @@ -55,4 +55,34 @@ expect(loader).to have_received(:setup).once end end + + describe "#run!" do + subject(:run!) { application.run!(argv) } + + let(:argv) { %w[foo bar baz] } + + let(:command) { instance_spy(Kangaru::Command) } + + let(:router) { instance_spy(Kangaru::Router) } + + before do + allow(Kangaru::Command).to receive(:parse).and_return(command) + allow(Kangaru::Router).to receive(:new).and_return(router) + end + + it "parses the arguments into a command" do + run! + expect(Kangaru::Command).to have_received(:parse).with(argv) + end + + it "instantiates a router" do + run! + expect(Kangaru::Router).to have_received(:new).with(command, namespace:) + end + + it "resolves the request" do + run! + expect(router).to have_received(:resolve) + end + end end