spec/middleware/dispatch_spec.rb in wayfarer-0.4.6 vs spec/middleware/dispatch_spec.rb in wayfarer-0.4.7

- old
+ new

@@ -6,34 +6,50 @@ let(:task) { build(:task) } let(:action) { :action } subject(:chain) { described_class.new } before do - task.metadata.controller = spy - task.metadata.action = action + task[:controller] = spy + task[:action] = action - allow(task.metadata.controller).to receive(:run_callbacks).and_yield + allow(task[: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) + expect(task[: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) + expect(task[:controller]).to receive(action) subject.call(task) end end - context "with other action" do - let(:action) { Class.new } + context "with handler" do + let(:action) { Class.new.include(Wayfarer::Handler) } it "instantiates and calls" do expect_any_instance_of(action).to receive(:call).with(task) subject.call(task) + end + end + + context "without action" do + let(:action) { nil } + + it "instantiates and calls" do + expect { subject.call(task) }.to raise_error(ArgumentError) + end + end + + context "without other action" do + let(:action) { Class.new } + + it "instantiates and calls" do + expect { subject.call(task) }.to raise_error(ArgumentError) end end it "yields" do expect { |spy| subject.call(task, &spy) }.to yield_control