Module: RosettaQueue::SpecHelpers

Defined in:
lib/rosetta_queue/spec_helpers/helpers.rb

Overview

Adds helpful methods when doing application level testing. If you are using cucumber just include it in your World in the env.rb file: World {|world| world.extend RosettaQueue::SpecHelpers }

Instance Method Summary collapse

Instance Method Details

#clear_queuesObject

Currently only works with ActiveMQ being used as gateway. This will clear the queues defined in the RosettaQueue::Destinations mapping. TODO: Figure out a better spot for this to allow for other gateways…



11
12
13
14
15
16
# File 'lib/rosetta_queue/spec_helpers/helpers.rb', line 11

def clear_queues
  RosettaQueue::Destinations.queue_names.each do |name| 
    queue = name.gsub('/queue/','')
    open("http://127.0.0.1:8161/admin/deleteDestination.action?JMSDestination=#{queue}&JMSDestinationType=queue")
  end
end

#consume_once(dest) ⇒ Object

Consumes the first message on queue and returns it. Example: message = consume_once :foo_queue



37
38
39
# File 'lib/rosetta_queue/spec_helpers/helpers.rb', line 37

def consume_once(dest)
  RosettaQueue::Consumer.receive(dest)
end

#consume_once_with(consumer) ⇒ Object

Consumes the first message on queue of consumer that is passed in and uses the consumer to handle it. Example: consume_once_with ClientStatusConsumer



30
31
32
# File 'lib/rosetta_queue/spec_helpers/helpers.rb', line 30

def consume_once_with(consumer)
  consumer.new.on_message(RosettaQueue::Consumer.receive(consumer.destination))
end

#consuming_from(destination) ⇒ Object



41
42
43
44
# File 'lib/rosetta_queue/spec_helpers/helpers.rb', line 41

def consuming_from(destination)
  sleep 1
  Messaging::Consumer.receive(destination, :persistent => false).to_hash_from_json
end

#publish_message(message, options) ⇒ Object

Publishes a given hash as json to the specified destination. Example: publish_message(expected_message, :to => :client_status, :options => …) The :options will be passed to the publisher and are optional.



22
23
24
25
# File 'lib/rosetta_queue/spec_helpers/helpers.rb', line 22

def publish_message(message, options)
  options[:options] ||= {:persistent => false}
  RosettaQueue::Producer.publish(options[:to], message, options[:options])
end