Sha256: db11d553daaa64ba96d8be0cebce4d4cd197548951d40673f979f892c74dc840

Contents?: true

Size: 1.98 KB

Versions: 3

Compression:

Stored size: 1.98 KB

Contents

require File.dirname(__FILE__) + '/../spec_helper'

module RosettaQueue
  
  class TestProducer < Producer

    publishes_to :test_queue
    options :persistent => false

  end
  
  describe Producer do    
    
    before(:each) do
      @adapter = mock("adapter", :send_message => nil)
      RosettaQueue::Adapter.stub!(:instance).and_return(@adapter)
      @gateway  = TestProducer.new
      
      Destinations.stub!(:lookup).and_return("/queue/test_queue")
    end
    
    it_should_behave_like "a messaging gateway object"
    attr_reader :adapter, :gateway
    
    
    describe "#publish" do
      
      before(:each) do
        @adapter = mock("adpater", :send_message => nil)
        RosettaQueue::Adapter.stub!(:instance).and_return(@adapter)
      end
      
      # it "should look up the destination defined on the class" do
      #   Destinations.should_receive(:lookup).with(:test_queue).and_return("/queue/test_queue")
      #   # when
      #    @gateway.publish('some message')
      # end

      it "should publish messages to queue with the options defined in the class" do        
        # TO DO: REFACTOR #publish METHOD SO THAT YOU PASS IN MESSAGE HANDLER AS WITH CONSUMER
        pending
        # expect
        @adapter.should_receive(:send_message).with("/queue/test_queue", "Hello World!", {:persistent => false})
        # when
        @gateway.publish("Hello World!")
      end

    end
    
    describe ".publish" do
      # it "should look up the destination defined on the class" do
      #   Destinations.should_receive(:lookup).with(:test_queue).and_return("/queue/test_queue")
      #   # when
      #   Producer.publish(:test_queue, "blah")
      # end
      
      it "should send the message to the adpater along with the options" do
        # expect
        @adapter.should_receive(:send_message).with("/queue/test_queue", "Hello World!", {:persistent => true})
        # when
        Producer.publish(:test_queue, "Hello World!", {:persistent => true})
      end
    end
    
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
bmabey-rosetta_queue-0.1.3 spec/rosetta_queue/producer_spec.rb
bmabey-rosetta_queue-0.2.0 spec/rosetta_queue/producer_spec.rb
cwyckoff-rosetta_queue-0.3.3 spec/rosetta_queue/producer_spec.rb