diff --git a/lib/kangaru/router.rb b/lib/kangaru/router.rb index 9a3b4bf..9988a1a 100644 --- a/lib/kangaru/router.rb +++ b/lib/kangaru/router.rb @@ -16,6 +16,10 @@ def initialize(command, namespace: Object) validate_action_defined! end + def resolve + controller_class.new(command).execute + end + private def controller_class diff --git a/sig/kangaru/router.rbs b/sig/kangaru/router.rbs index be0820d..ea006f5 100644 --- a/sig/kangaru/router.rbs +++ b/sig/kangaru/router.rbs @@ -11,6 +11,8 @@ module Kangaru def initialize: (Command, ?namespace: Module) -> void + def resolve: -> void + private @controller_class: untyped diff --git a/spec/kangaru/router_spec.rb b/spec/kangaru/router_spec.rb index 8736e6a..c236375 100644 --- a/spec/kangaru/router_spec.rb +++ b/spec/kangaru/router_spec.rb @@ -55,4 +55,24 @@ end end end + + describe "#resolve" do + subject(:resolve) { router.resolve } + + let(:controller_spy) { instance_spy(controller_class) } + + before do + allow(controller_class).to receive(:new).and_return(controller_spy) + end + + it "instantiates a controller instance" do + resolve + expect(controller_class).to have_received(:new).with(command) + end + + it "triggers the controller to execute the command" do + resolve + expect(controller_spy).to have_received(:execute).once + end + end end