spec/lib/dispatch-rider/subscriber_spec.rb in dispatch-rider-1.6.0 vs spec/lib/dispatch-rider/subscriber_spec.rb in dispatch-rider-1.6.1
- old
+ new
@@ -1,8 +1,16 @@
require "spec_helper"
describe DispatchRider::Subscriber do
+ let(:message_subject) { "handle_something" }
+ let(:message_body) { { do_throw_something: true } }
+ let(:fs_message) do
+ DispatchRider::Message.new(subject: message_subject, body: message_body.merge('guid' => 123))
+ end
+ let(:item) { double :item }
+ let(:queue) { double :queue }
+ let(:message) { DispatchRider::QueueServices::FileSystem::FsReceivedMessage.new(fs_message, item, queue) }
before do
allow(DispatchRider::Handlers::Base).to receive(:subclasses) { Set.new }
konst = Class.new(DispatchRider::Handlers::Base) do
@@ -25,24 +33,23 @@
expect(subject.queue_service_registrar.fetch(:simple)).to be_empty
end
end
describe "#register_handler" do
+ let(:message_subject) { :foo_bar }
+ let(:message_body) { { 'foo' => 'bar' } }
+
it "should register a handler" do
subject.register_handler(:foo_bar)
expect {
- message = DispatchRider::Message.new(subject: :foo_bar, body: { 'foo' => 'bar' })
subject.dispatcher.dispatch(message)
}.to throw_symbol(:process_was_called)
end
- end
- describe "#register_handlers" do
it "should register all the handlers" do
subject.register_handlers(:foo_bar)
expect {
- message = DispatchRider::Message.new(subject: :foo_bar, body: { 'foo' => 'bar' })
subject.dispatcher.dispatch(message)
}.to throw_symbol(:process_was_called)
end
end
@@ -80,61 +87,63 @@
end
# kills travis sometimes so leaving it here as tested documentation
describe "process termination", if: false do
before { allow(subject.demultiplexer).to receive(:stop) { throw :got_stopped } }
+ let(:message_body) { { 'foo' => 'bar' } }
context "when process quits" do
+ let(:message_subject) { :quiter }
before do
konst = Class.new(DispatchRider::Handlers::Base) do
def process(_options)
Process.kill("QUIT", 0)
end
end
stub_const("Quiter", konst)
subject.register_handler(:quiter)
- message = DispatchRider::Message.new(subject: :quiter, body: {})
subject.queue_service_registrar.fetch(:simple).push(message)
end
example { expect { subject.process }.to throw_symbol(:got_stopped) }
end
context "when process terminates" do
+ let(:message_subject) { :terminator }
before do
konst = Class.new(DispatchRider::Handlers::Base) do
def process(_options)
Process.kill("TERM", 0)
end
end
stub_const("Terminator", konst)
subject.register_handler(:terminator)
- message = DispatchRider::Message.new(subject: :terminator, body: {})
subject.queue_service_registrar.fetch(:simple).push(message)
end
example { expect { subject.process }.to throw_symbol(:got_stopped) }
end
context "when process is interupted" do
+ let(:message_subject) { :interupter }
before do
konst = Class.new(DispatchRider::Handlers::Base) do
def process(_options)
Process.kill("INT", 0)
end
end
stub_const("Interupter", konst)
subject.register_handler(:interupter)
- message = DispatchRider::Message.new(subject: :interupter, body: {})
subject.queue_service_registrar.fetch(:simple).push(message)
end
example { expect { subject.process }.to throw_symbol(:got_stopped) }
end
context "when process is interupted twice" do
+ let(:message_subject) { :twice_interupter }
before do
allow(subject.demultiplexer).to receive(:stop) # do nothing just ignore the interuption
allow(subject).to receive(:exit) { throw :got_forcefully_stopped }
konst = Class.new(DispatchRider::Handlers::Base) do
@@ -142,10 +151,9 @@
2.times { Process.kill("INT", 0) }
end
end
stub_const("TwiceInterupter", konst)
subject.register_handler(:twice_interupter)
- message = DispatchRider::Message.new(subject: :twice_interupter, body: {})
subject.queue_service_registrar.fetch(:simple).push(message)
end
example { expect { subject.process }.to throw_symbol(:got_forcefully_stopped) }
end