require "#{File.expand_path(File.dirname(__FILE__))}/helper" describe "Conveyor" do inject :conveyors => :conveyors with_environment :development def call_conveyor r = conveyors.web.call(:result => []) r.result end it "smoke test" do class SmokeTestASpec < Crystal::Processor def call workspace.result << :a_before next_processor.call workspace.result << :a_after end end class SmokeTestBSpec < Crystal::Processor def call crystal[:workspace].result << :b_before next_processor.call crystal[:workspace].result << :b_after end end conveyors.web.use SmokeTestASpec conveyors.web.use SmokeTestBSpec call_conveyor.should == [:a_before, :b_before, :b_after, :a_after] end describe "error handling" do it "common case" do class CommonCaseASpec < Crystal::Processor def call workspace.result << :a_before begin next_processor.call rescue StandardError => e workspace.result << e.message end end end class CommonCaseBSpec < Crystal::Processor def call workspace.result << :b_before raise 'error before' end end conveyors.web.use CommonCaseASpec conveyors.web.use CommonCaseBSpec call_conveyor.should == [:a_before, :b_before, "error before"] end it "should raise error if not catched" do class NotCatchedErrorSpec < Crystal::Processor def call workspace.result << :before raise 'error before' end end conveyors.web.use NotCatchedErrorSpec lambda{call_conveyor}.should raise_error(/error before/) end it "in after block" do class ErrorInAfterBlockASpec < Crystal::Processor def call workspace.result << :a_before begin next_processor.call rescue StandardError => e workspace.result << e.message end end end class ErrorInAfterBlockBSpec < Crystal::Processor def call workspace.result << :b_before next_processor.call raise 'error after' end end conveyors.web.use ErrorInAfterBlockASpec conveyors.web.use ErrorInAfterBlockBSpec call_conveyor.should == [:a_before, :b_before, "error after"] end it "bubbling (from error)" do class ErrorBubblingASpec < Crystal::Processor def call begin next_processor.call rescue RuntimeError => e workspace.result << e.message end end end class ErrorBubblingBSpec < Crystal::Processor def call raise 'error' end end conveyors.web.use ErrorBubblingASpec conveyors.web.use ErrorBubblingBSpec call_conveyor.should == ['error'] end end end