test/services/queue_creator_test.rb in propono-1.4.0 vs test/services/queue_creator_test.rb in propono-1.5.0
- old
+ new
@@ -1,12 +1,30 @@
require File.expand_path('../../test_helper', __FILE__)
module Propono
class QueueCreatorTest < Minitest::Test
- def test_create_topic_called_on_sqs
- sqs = mock()
+ def test_finds_existing_url
+ name = "foobar"
+ url = "http://#{name}"
+ sqs = Fog::AWS::SQS::Mock.new
+ sqs.stubs(:list_queues)
+ sqs.expects(:list_queues).
+ with("QueueNamePrefix" => "#{name}").
+ returns(
+ mock(body: { "QueueUrls" => [url]})
+ )
+
+ creator = QueueCreator.new(name)
+ creator.stubs(sqs: sqs)
+
+ queue = creator.find_or_create
+ assert_equal url, queue.url
+ end
+
+ def test_create_queue_called_on_sqs
+ sqs = Fog::AWS::SQS::Mock.new
sqs.expects(:create_queue).with("foobar").returns(mock(body: { "QueueUrl" => "Foobar"}))
creator = QueueCreator.new("foobar")
creator.stubs(sqs: sqs)
@@ -14,21 +32,23 @@
end
def test_returns_url
url = "malcs_happy_queue"
result = mock(body: { "QueueUrl" => url})
- sqs = mock(create_queue: result)
+ sqs = Fog::AWS::SQS::Mock.new
+ sqs.expects(create_queue: result)
creator = QueueCreator.new("foobar")
creator.stubs(sqs: sqs)
queue = creator.find_or_create
assert_equal url, queue.url
end
def test_should_raise_exception_if_no_queue_returned
result = mock(body: {})
- sqs = mock(create_queue: result)
+ sqs = Fog::AWS::SQS::Mock.new
+ sqs.expects(create_queue: result)
creator = QueueCreator.new("foobar")
creator.stubs(sqs: sqs)
assert_raises QueueCreatorError do