spec/units/message_driver/broker_spec.rb in message-driver-0.1.0 vs spec/units/message_driver/broker_spec.rb in message-driver-0.2.0.rc1
- old
+ new
@@ -1,24 +1,46 @@
require 'spec_helper'
require 'message_driver/adapters/in_memory_adapter'
module MessageDriver
describe Broker do
- subject(:broker) { described_class.new(adapter: :in_memory) }
+ let(:options) { { adapter: :in_memory } }
+ before do
+ described_class.configure(options)
+ end
+ subject(:broker) { described_class.instance }
describe ".configure" do
it "calls new, passing in the options and saves the instance" do
options = {foo: :bar}
- result = stub(described_class)
+ result = double(described_class)
described_class.should_receive(:new).with(options).and_return(result)
described_class.configure(options)
expect(described_class.instance).to be result
end
end
+ describe "#logger" do
+ it "returns the logger, which logs at the info level" do
+ expect(subject.logger).to be_a Logger
+ expect(subject.logger).to be_info
+ expect(subject.logger).to_not be_debug
+ end
+
+ context "configuring the logger" do
+ let(:logger) { double(Logger).as_null_object }
+ let(:options) { { adapter: :in_memory, logger: logger } }
+
+ it "returns the provided logger" do
+ actual = subject.logger
+ expect(actual).to be logger
+ end
+ end
+ end
+
describe "#initialize" do
it "raises an error if you don't specify an adapter" do
expect {
described_class.new({})
}.to raise_error(/must specify an adapter/)
@@ -60,39 +82,70 @@
instance = described_class.new(config)
expect(instance.configuration).to be config
end
end
- describe "#publish" do
- it "needs some real tests"
+ describe "#destination" do
+ it "returns the destination" do
+ destination = broker.destination(:my_queue, "my_queue", exclusive: true)
+ expect(destination).to be_a MessageDriver::Destination::Base
+ end
+ end
+ describe "#find_destination" do
+ it "finds the previously defined destination" do
+ my_destination = broker.destination(:my_queue, "my_queue", exclusive: true)
+ expect(broker.find_destination(:my_queue)).to be(my_destination)
+ end
+
context "when the destination can't be found" do
- it "raises an error"
+ let(:bad_dest_name) { :not_a_queue }
+ it "raises a MessageDriver:NoSuchDestinationError" do
+ expect {
+ broker.find_destination(bad_dest_name)
+ }.to raise_error(MessageDriver::NoSuchDestinationError, /#{bad_dest_name}/)
+ end
end
end
- describe "#pop_message" do
- it "needs some real tests"
- context "when the destination can't be found" do
- it "raises an error"
+ describe "#consumer" do
+ let(:consumer_double) { lambda do |m| end }
+ it "saves the provided consumer" do
+ broker.consumer(:my_consumer, &consumer_double)
+ expect(broker.consumers[:my_consumer]).to be(consumer_double)
end
+
+ context "when no consumer is provided" do
+ it "raises an error" do
+ expect {
+ broker.consumer(:my_consumer)
+ }.to raise_error(MessageDriver::Error, "you must provide a block")
+ end
+ end
end
- describe "#destination" do
- it "needs some real tests"
+ describe "#find_consumer" do
+ let(:consumer_double) { lambda do |m| end }
+ it "finds the previously defined consumer" do
+ my_consumer = broker.consumer(:my_consumer, &consumer_double)
+ expect(broker.find_consumer(:my_consumer)).to be(my_consumer)
+ end
+
+ context "when the consumer can't be found" do
+ let(:bad_consumer_name) { :not_a_queue }
+ it "raises a MessageDriver:NoSuchConsumerError" do
+ expect {
+ broker.find_consumer(bad_consumer_name)
+ }.to raise_error(MessageDriver::NoSuchConsumerError, /#{bad_consumer_name}/)
+ end
+ end
end
describe "#dynamic_destination" do
it "returns the destination" do
destination = broker.dynamic_destination("my_queue", exclusive: true)
expect(destination).to be_a MessageDriver::Destination::Base
end
- it "doesn't save the destination" do
- destination = nil
- expect {
- destination = broker.dynamic_destination("my_queue", exclusive: true)
- }.to_not change{broker.destinations.size}
- expect(broker.destinations.values).to_not include(destination)
- end
end
+
end
end