Skip to content

Commit

Permalink
Implement Application#run!
Browse files Browse the repository at this point in the history
  • Loading branch information
apexatoll committed Sep 22, 2023
1 parent 1d12ef7 commit 461ad08
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/kangaru/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions sig/kangaru/application.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ module Kangaru

def setup: -> void

def run!: (Array[String]) -> void

private

attr_reader autoloader: Zeitwerk::Loader
Expand Down
30 changes: 30 additions & 0 deletions spec/kangaru/application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 461ad08

Please sign in to comment.