diff --git a/lib/pipefy_message.rb b/lib/pipefy_message.rb index e161624..d91fef0 100644 --- a/lib/pipefy_message.rb +++ b/lib/pipefy_message.rb @@ -8,6 +8,7 @@ require_relative "pipefy_message/logger" require_relative "pipefy_message/worker" require_relative "pipefy_message/providers/broker" +require_relative "pipefy_message/providers/errors" require "logger" module PipefyMessage diff --git a/lib/pipefy_message/providers/errors.rb b/lib/pipefy_message/providers/errors.rb new file mode 100644 index 0000000..623d182 --- /dev/null +++ b/lib/pipefy_message/providers/errors.rb @@ -0,0 +1,11 @@ +module PipefyMessage + module Providers + module Errors + class ResourceError < StandardError + def initialize(msg="ResourceError") + super + end + end + end + end +end \ No newline at end of file diff --git a/spec/worker_spec.rb b/spec/worker_spec.rb index 0472e50..5f2b9b5 100644 --- a/spec/worker_spec.rb +++ b/spec/worker_spec.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true -RSpec.describe PipefyMessage::Worker do +RSpec.describe PipefyMessage::Worker do + $result =~ nil class MockBroker < PipefyMessage::Providers::Broker @@ -10,13 +11,13 @@ def poller end class MockBrokerFail < PipefyMessage::Providers::Broker def poller - raise Exception.new "This is an exception" + raise PipefyMessage::Providers::Errors::ResourceError end end class TestWorker include PipefyMessage::Worker - pipefymessage_options broker: "aws", queue: "http://localhost:4566/000000000000/pipefy-local-queue" + pipefymessage_options broker: "aws", queue: "pipefy-local-queue" def perform(message) puts message @@ -26,15 +27,15 @@ def perform(message) describe "#perform" do it "should call #perform from child instance when call #perform_async with success" do - # allow(TestWorker).to receive(:build_instance_broker).and_return(MockBroker.new) + allow(TestWorker).to receive(:build_instance_broker).and_return(MockBroker.new) TestWorker.perform_async expect($result).to eq "test" end - it "should call #perform from child instance when call #perform_async with fail(raise a exception)" do + it "should call #perform from child instance when call #perform_async with fail(raise a ResourceError)" do allow(TestWorker).to receive(:build_instance_broker).and_return(MockBrokerFail.new) - expect{ TestWorker.perform_async }.to raise_error(Exception, /This is an exception/) + expect{ TestWorker.perform_async }.to raise_error(PipefyMessage::Providers::Errors::ResourceError) end end