# frozen_string_literal: true require "spec_helpers" describe Wayfarer::Middleware::Dispatch do let(:task) { build(:task) } let(:action) { :action } subject(:chain) { described_class.new } before do task.metadata.controller = spy task.metadata.action = action allow(task.metadata.controller).to receive(:run_callbacks).and_yield end describe "#call" do it "runs callbacks" do expect(task.metadata.controller).to receive(:run_callbacks).with(action) subject.call(task) end context "when action is a Symbol" do it "calls the method" do expect(task.metadata.controller).to receive(action) subject.call(task) end end context "with other action" do let(:action) { Class.new } it "instantiates and calls" do expect_any_instance_of(action).to receive(:call).with(task) subject.call(task) end end it "yields" do expect { |spy| subject.call(task, &spy) }.to yield_control end end end