Skip to content
This repository has been archived by the owner on Apr 5, 2023. It is now read-only.

Commit

Permalink
feat: add resourceError
Browse files Browse the repository at this point in the history
  • Loading branch information
eHattori committed Apr 19, 2022
1 parent c7e2dd6 commit 109a8f3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/pipefy_message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions lib/pipefy_message/providers/errors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module PipefyMessage
module Providers
module Errors
class ResourceError < StandardError
def initialize(msg="ResourceError")
super
end
end
end
end
end
13 changes: 7 additions & 6 deletions spec/worker_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 109a8f3

Please sign in to comment.