govuk_message_queue_consumer 2.1.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ea5c6560ba396d9f32d22371cd8f94240bdfbcd
4
- data.tar.gz: fdc543d6ee7d1290e3df4db3628f497aa3151e37
3
+ metadata.gz: d4a095426507f671b2ed962c5fcd7fd2a8b8562a
4
+ data.tar.gz: 7b5611a301ea24405a3b2fc83e18e436480f6123
5
5
  SHA512:
6
- metadata.gz: 760eb4893ce343d4e5dc439bc05a80ef49ceb8fc9c4538395079f6644b05ad555e435e32415be004bb0116dd1d9ec8b54bedf62819bf8eceaf7ac1caa3ce8451
7
- data.tar.gz: 98f3ff7cb41cb8f20233114121e53967d180462ecd1118c07d0abf409456ca3c663127c6e2692f8a7cbadaa250bf2e36ba65e4865a45edf160a3d6f6d9e71374
6
+ metadata.gz: cf97eb5b97d6a202224689afc7d4b8a79e21bbbdba16337d54f2ad52b5404a0bae7fea90dde0865230fecb40419cab9555b027db06d561089a1862321c737789
7
+ data.tar.gz: 6dd646bfd603d17f827b91ff5cf19c48bf24c0f732bc9bfc6e7f8ade85cf5ea3954f0f002c12e3b901b2f288893de3b786e03d0f26cabc9f9bb753f129075871
data/CHANGELOG.md ADDED
@@ -0,0 +1,42 @@
1
+ # 3.0.0
2
+
3
+ - Updated README to conform changes on [PR #32](https://github.com/alphagov/govuk_message_queue_consumer/pull/32)
4
+ - Remove `exchange_name` parameter [PR #34](https://github.com/alphagov/govuk_message_queue_consumer/pull/34)
5
+ - Don't build test files in the gem [PR #33](https://github.com/alphagov/govuk_message_queue_consumer/pull/33)
6
+ - Prevent consumer from creating rabbitmq queues or bindings [PR #32](https://github.com/alphagov/govuk_message_queue_consumer/pull/32)
7
+
8
+ # 2.1.0
9
+
10
+ - Add support for sending stats to Statsd
11
+
12
+ # 2.0.1
13
+
14
+ * Add support for Airbrake.
15
+
16
+ # 2.0.0
17
+
18
+ - README updates making it clearer how to use the gem
19
+ - Use environment variables for RabbitMQ configuration
20
+ - Use keyword arguments for the `Consumer` setup
21
+ - Add rspec shared examples for testing a message processor
22
+ - Add `GovukMessageQueueConsumer::MockMessage` for easy testing
23
+ - Add `GovukMessageQueueConsumer::JSONProcessor` as an intermediate processor for JSON payloads
24
+ - Add Airbrake notification for gem errors
25
+ - Remove active_support dependency
26
+
27
+ # 1.0.0
28
+
29
+ - Rename the gem to `govuk_message_queue_consumer`
30
+ - Make test helpers easier to use
31
+ - Readme improvements
32
+ - Initial release!
33
+
34
+ # 0.9.1
35
+
36
+ Bug fix:
37
+ - relax the ruby version as it's causing problems in projects trying to use it
38
+
39
+
40
+ # 0.9.0
41
+
42
+ - Initial implementation of the gem
data/LICENCE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+ Copyright (C) 2015 Crown copyright (Government Digital Service)
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ this software and associated documentation files (the "Software"), to deal in
6
+ the Software without restriction, including without limitation the rights to
7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8
+ of the Software, and to permit persons to whom the Software is furnished to do
9
+ so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
data/README.md CHANGED
@@ -65,8 +65,7 @@ namespace :message_queue do
65
65
  task consumer: :environment do
66
66
  GovukMessageQueueConsumer::Consumer.new(
67
67
  queue_name: "some-queue",
68
- exchange_name: "some-exchange",
69
- processor: MyProcessor.new
68
+ processor: MyProcessor.new,
70
69
  ).run
71
70
  end
72
71
  end
@@ -1,6 +1,3 @@
1
- require 'bunny'
2
- require_relative 'null_statsd'
3
-
4
1
  module GovukMessageQueueConsumer
5
2
  class Consumer
6
3
  # Only fetch one message at a time on the channel.
@@ -14,20 +11,23 @@ module GovukMessageQueueConsumer
14
11
 
15
12
  # Create a new consumer
16
13
  #
17
- # @param queue_name [String] Your queue name. This is specific to your application.
18
- # @param exchange_name [String] Name of the exchange to bind to, for example `published_documents`
14
+ # @param queue_name [String] Your queue name. This is specific to your application,
15
+ # and should already exist and have a binding via puppet
19
16
  # @param processor [Object] An object that responds to `process`
20
- # @param routing_key [String] The RabbitMQ routing key to bind the queue to
17
+ # @param rabbitmq_connection [Object] A Bunny connection object derived from `Bunny.new`
21
18
  # @param statsd_client [Statsd] An instance of the Statsd class
22
- def initialize(queue_name:, exchange_name:, processor:, routing_key: '#', statsd_client: NullStatsd.new)
19
+ # @param logger [Object] A Logger object for emitting errors (to stderr by default)
20
+ def initialize(queue_name:, processor:, rabbitmq_connection: Consumer.default_connection_from_env, statsd_client: NullStatsd.new, logger: Logger.new(STDERR))
23
21
  @queue_name = queue_name
24
- @exchange_name = exchange_name
25
22
  @processor = processor
26
- @routing_key = routing_key
23
+ @rabbitmq_connection = rabbitmq_connection
27
24
  @statsd_client = statsd_client
25
+ @logger = logger
28
26
  end
29
27
 
30
28
  def run
29
+ @rabbitmq_connection.start
30
+
31
31
  queue.subscribe(block: true, manual_ack: true) do |delivery_info, headers, payload|
32
32
  begin
33
33
  message = Message.new(payload, headers, delivery_info)
@@ -37,7 +37,7 @@ module GovukMessageQueueConsumer
37
37
  rescue Exception => e
38
38
  @statsd_client.increment("#{@queue_name}.uncaught_exception")
39
39
  Airbrake.notify_or_ignore(e) if defined?(Airbrake)
40
- $stderr.puts "Uncaught exception in processor: \n\n #{e.class}: #{e.message}\n\n#{e.backtrace.join("\n")}"
40
+ @logger.error "Uncaught exception in processor: \n\n #{e.class}: #{e.message}\n\n#{e.backtrace.join("\n")}"
41
41
  exit(1) # Ensure rabbitmq requeues outstanding messages
42
42
  end
43
43
  end
@@ -45,6 +45,11 @@ module GovukMessageQueueConsumer
45
45
 
46
46
  private
47
47
 
48
+ class NullStatsd
49
+ def increment(_key)
50
+ end
51
+ end
52
+
48
53
  def processor_chain
49
54
  @processor_chain ||= HeartbeatProcessor.new(JSONProcessor.new(@processor))
50
55
  end
@@ -52,26 +57,16 @@ module GovukMessageQueueConsumer
52
57
  def queue
53
58
  @queue ||= begin
54
59
  channel.prefetch(NUMBER_OF_MESSAGES_TO_PREFETCH)
55
- queue = channel.queue(@queue_name, durable: true)
56
- queue.bind(exchange, routing_key: @routing_key)
57
- queue
60
+ channel.queue(@queue_name, no_declare: true)
58
61
  end
59
62
  end
60
63
 
61
- def exchange
62
- @exchange ||= channel.topic(@exchange_name, passive: true)
63
- end
64
-
65
64
  def channel
66
- @channel ||= connection.create_channel
65
+ @channel ||= @rabbitmq_connection.create_channel
67
66
  end
68
67
 
69
- def connection
70
- @connection ||= begin
71
- new_connection = Bunny.new(RabbitMQConfig.new.from_environment)
72
- new_connection.start
73
- new_connection
74
- end
68
+ def self.default_connection_from_env
69
+ Bunny.new(GovukMessageQueueConsumer::RabbitMQConfig.from_environment(ENV))
75
70
  end
76
71
  end
77
72
  end
@@ -1,5 +1,3 @@
1
- require 'json'
2
-
3
1
  module GovukMessageQueueConsumer
4
2
  # Client code will receive an instance of this
5
3
  class Message
@@ -1,29 +1,31 @@
1
- class RabbitMQConfig
2
- class ConfigurationError < StandardError
3
- end
1
+ module GovukMessageQueueConsumer
2
+ module RabbitMQConfig
3
+ class ConfigurationError < StandardError
4
+ end
4
5
 
5
- def from_environment
6
- {
7
- hosts: fetch("RABBITMQ_HOSTS").split(','),
8
- vhost: fetch("RABBITMQ_VHOST"),
9
- user: fetch("RABBITMQ_USER"),
10
- pass: fetch("RABBITMQ_PASSWORD"),
11
- recover_from_connection_close: true,
12
- }
13
- end
6
+ def self.from_environment(env)
7
+ {
8
+ hosts: fetch(env, "RABBITMQ_HOSTS").split(','),
9
+ vhost: fetch(env, "RABBITMQ_VHOST"),
10
+ user: fetch(env, "RABBITMQ_USER"),
11
+ pass: fetch(env, "RABBITMQ_PASSWORD"),
12
+ recover_from_connection_close: true,
13
+ }
14
+ end
14
15
 
15
- private
16
+ private
16
17
 
17
- def fetch(variable_name)
18
- ENV[variable_name] || raise_error(variable_name)
19
- end
18
+ def self.fetch(env, variable_name)
19
+ env[variable_name] || raise_error(variable_name)
20
+ end
20
21
 
21
- def raise_error(variable_name)
22
- raise ConfigurationError, <<-err
23
- The environment variable #{variable_name} is not set. If you are in test
24
- mode, make sure you set the correct vars in your helpers. If you get this
25
- error in development, make sure you run rails or rake with `govuk_setenv`
26
- and puppet is up to date.
27
- err
22
+ def self.raise_error(variable_name)
23
+ raise ConfigurationError, <<-err
24
+ The environment variable #{variable_name} is not set. If you are in test
25
+ mode, make sure you set the correct vars in your helpers. If you get this
26
+ error in development, make sure you run rails or rake with `govuk_setenv`
27
+ and puppet is up to date.
28
+ err
29
+ end
28
30
  end
29
31
  end
@@ -1,3 +1,3 @@
1
1
  module GovukMessageQueueConsumer
2
- VERSION = '2.1.0'
2
+ VERSION = '3.0.0'
3
3
  end
@@ -1,3 +1,6 @@
1
+ require 'bunny'
2
+ require 'json'
3
+
1
4
  require 'govuk_message_queue_consumer/version'
2
5
  require 'govuk_message_queue_consumer/heartbeat_processor'
3
6
  require 'govuk_message_queue_consumer/json_processor'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_message_queue_consumer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-06 00:00:00.000000000 Z
11
+ date: 2016-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -88,28 +88,19 @@ executables: []
88
88
  extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
+ - CHANGELOG.md
92
+ - LICENCE
91
93
  - README.md
92
- - Rakefile
93
94
  - lib/govuk_message_queue_consumer.rb
94
95
  - lib/govuk_message_queue_consumer/consumer.rb
95
96
  - lib/govuk_message_queue_consumer/heartbeat_processor.rb
96
97
  - lib/govuk_message_queue_consumer/json_processor.rb
97
98
  - lib/govuk_message_queue_consumer/message.rb
98
- - lib/govuk_message_queue_consumer/null_statsd.rb
99
99
  - lib/govuk_message_queue_consumer/rabbitmq_config.rb
100
100
  - lib/govuk_message_queue_consumer/test_helpers.rb
101
101
  - lib/govuk_message_queue_consumer/test_helpers/mock_message.rb
102
102
  - lib/govuk_message_queue_consumer/test_helpers/shared_examples.rb
103
- - lib/govuk_message_queue_consumer/test_helpers/test_consumer.rb
104
103
  - lib/govuk_message_queue_consumer/version.rb
105
- - spec/consumer_spec.rb
106
- - spec/consumer_with_statsd_spec.rb
107
- - spec/heartbeat_processor_spec.rb
108
- - spec/json_processor_spec.rb
109
- - spec/message_spec.rb
110
- - spec/mock_message_spec.rb
111
- - spec/rabbitmq_config_spec.rb
112
- - spec/spec_helper.rb
113
104
  homepage: https://github.com/alphagov/govuk_message_queue_consumer
114
105
  licenses: []
115
106
  metadata: {}
@@ -133,13 +124,5 @@ rubygems_version: 2.4.5.1
133
124
  signing_key:
134
125
  specification_version: 4
135
126
  summary: AMQP message queue consumption with GOV.UK conventions
136
- test_files:
137
- - spec/heartbeat_processor_spec.rb
138
- - spec/spec_helper.rb
139
- - spec/message_spec.rb
140
- - spec/consumer_spec.rb
141
- - spec/consumer_with_statsd_spec.rb
142
- - spec/mock_message_spec.rb
143
- - spec/json_processor_spec.rb
144
- - spec/rabbitmq_config_spec.rb
127
+ test_files: []
145
128
  has_rdoc:
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- require 'rspec/core/rake_task'
2
- RSpec::Core::RakeTask.new(:spec)
3
-
4
- # Load local tasks
5
- Dir['tasks/**/*.rake'].each { |file| load file }
6
-
7
- task(:default).clear
8
- task :default => [:spec]
@@ -1,4 +0,0 @@
1
- class NullStatsd
2
- def increment(_key)
3
- end
4
- end
@@ -1,12 +0,0 @@
1
- module GovukMessageQueueConsumer
2
- class TestConsumer < Consumer
3
- def publish_message(payload, options)
4
- exchange.publish(payload, options)
5
- end
6
-
7
- # call after integration tests finish
8
- def delete_queue
9
- queue.delete
10
- end
11
- end
12
- end
@@ -1,36 +0,0 @@
1
- require_relative 'spec_helper'
2
- require_relative 'support/queue_helpers'
3
-
4
- describe Consumer do
5
- include QueueHelpers
6
-
7
- let(:client_processor) { instance_double('Client::Processor') }
8
-
9
- describe "#run" do
10
- it "binds the queue to the all-routing key" do
11
- queue = create_stubbed_queue
12
-
13
- expect(queue).to receive(:bind).with(nil, { routing_key: "#" })
14
-
15
- Consumer.new(queue_name: "some-queue", exchange_name: "my-exchange", processor: client_processor).run
16
- end
17
-
18
- it "binds the queue to a custom routing key" do
19
- queue = create_stubbed_queue
20
-
21
- expect(queue).to receive(:bind).with(nil, { routing_key: "*.major" })
22
-
23
- Consumer.new(queue_name: "some-queue", exchange_name: "my-exchange", processor: client_processor, routing_key: "*.major").run
24
- end
25
-
26
- it "calls the heartbeat processor when subscribing to messages" do
27
- queue = create_stubbed_queue
28
-
29
- expect(queue).to receive(:subscribe).and_yield(:delivery_info_object, :headers, "payload")
30
-
31
- expect_any_instance_of(HeartbeatProcessor).to receive(:process).with(kind_of(Message))
32
-
33
- Consumer.new(queue_name: "some-queue", exchange_name: "my-exchange", processor: client_processor).run
34
- end
35
- end
36
- end
@@ -1,54 +0,0 @@
1
- require_relative 'spec_helper'
2
- require_relative 'support/queue_helpers'
3
-
4
- describe Consumer do
5
- include QueueHelpers
6
-
7
- describe "#run" do
8
- it "increments the counters on the statsd client" do
9
- statsd_client = StatsdClientMock.new
10
- queue = create_stubbed_queue
11
-
12
- expect(queue).to receive(:subscribe).and_yield(
13
- double(:delivery_info, channel: double(:channel, reject: double), delivery_tag: double),
14
- double(:headers, content_type: 'application/json'),
15
- "message_payload"
16
- )
17
-
18
- Consumer.new(queue_name: "some-queue", exchange_name: "my-exchange", processor: double, statsd_client: statsd_client).run
19
-
20
- expect(statsd_client.incremented_keys).to eql(['some-queue.started', 'some-queue.discarded'])
21
- end
22
-
23
- it "increments the uncaught_exception counter for uncaught exceptions" do
24
- statsd_client = StatsdClientMock.new
25
- queue = create_stubbed_queue
26
-
27
- expect(queue).to receive(:subscribe).and_yield(
28
- double(:delivery_info, channel: double(:channel, reject: double), delivery_tag: double),
29
- double(:headers, content_type: 'application/json'),
30
- {}.to_json
31
- )
32
-
33
- processor = double
34
- expect(processor).to receive(:process).and_raise("An exception")
35
-
36
- expect do
37
- Consumer.new(queue_name: "some-queue", exchange_name: "my-exchange", processor: processor, statsd_client: statsd_client).run
38
- end.to raise_error(SystemExit)
39
-
40
- expect(statsd_client.incremented_keys).to eql(['some-queue.started', 'some-queue.uncaught_exception'])
41
- end
42
- end
43
-
44
- class StatsdClientMock
45
- attr_reader :incremented_keys
46
- def initialize
47
- @incremented_keys = []
48
- end
49
-
50
- def increment(key)
51
- @incremented_keys << key
52
- end
53
- end
54
- end
@@ -1,43 +0,0 @@
1
- require_relative 'spec_helper'
2
-
3
- describe HeartbeatProcessor do
4
- let(:heartbeat_headers) { instance_double("Heartbeat Headers", :content_type => "application/x-heartbeat") }
5
- let(:heartbeat_message) { instance_double("Heartbeat Message", :headers => heartbeat_headers, :ack => nil) }
6
- let(:standard_headers) { instance_double("Standard Headers", :content_type => nil) }
7
- let(:standard_message) { instance_double("Standard Message", :headers => standard_headers, :ack => nil) }
8
-
9
- let(:next_processor) { instance_double("Client::Processor") }
10
-
11
- subject {
12
- HeartbeatProcessor.new(next_processor)
13
- }
14
-
15
- context "for a heartbeat message" do
16
- it "doesn't call the next processor" do
17
- expect(next_processor).not_to receive(:process)
18
-
19
- subject.process(heartbeat_message)
20
- end
21
-
22
- it "acks the message" do
23
- expect(heartbeat_message).to receive(:ack)
24
-
25
- subject.process(heartbeat_message)
26
- end
27
- end
28
-
29
- context "for a content message" do
30
- it "calls the next processor" do
31
- expect(next_processor).to receive(:process).with(standard_message)
32
-
33
- subject.process(standard_message)
34
- end
35
-
36
- it "doesn't ack the message" do
37
- expect(standard_message).not_to receive(:ack)
38
- expect(next_processor).to receive(:process)
39
-
40
- subject.process(standard_message)
41
- end
42
- end
43
- end
@@ -1,33 +0,0 @@
1
- require_relative 'spec_helper'
2
-
3
- describe JSONProcessor do
4
- describe "#process" do
5
- it "parses the payload string" do
6
- next_processor = double("next_processor", process: "ha")
7
- message = MockMessage.new('{"some":"json"}', { content_type: "application/json" })
8
-
9
- JSONProcessor.new(next_processor).process(message)
10
-
11
- expect(message.payload).to eql({ "some" => "json" })
12
- expect(next_processor).to have_received(:process)
13
- end
14
-
15
- it "discards messages with JSON errors" do
16
- message = MockMessage.new('{"some" "json"}', { content_type: "application/json" })
17
-
18
- JSONProcessor.new(double).process(message)
19
-
20
- expect(message).to be_discarded
21
- end
22
-
23
- it "doesn't parse non-JSON message" do
24
- next_processor = double("next_processor", process: "ha")
25
- message = MockMessage.new('<SomeXML></SomeXML>', { content_type: "application/xml" })
26
-
27
- JSONProcessor.new(next_processor).process(message)
28
-
29
- expect(message.payload).to eql('<SomeXML></SomeXML>')
30
- expect(next_processor).to have_received(:process)
31
- end
32
- end
33
- end
data/spec/message_spec.rb DELETED
@@ -1,32 +0,0 @@
1
- require_relative 'spec_helper'
2
-
3
- describe Message do
4
- let(:mock_channel) { instance_double("Channel") }
5
- let(:delivery_info) { instance_double("DeliveryInfo", :channel => mock_channel, :delivery_tag => "a_tag") }
6
- let(:headers) { instance_double("Headers") }
7
- let(:message) { Message.new({ "a" => "payload" }, headers, delivery_info) }
8
-
9
- it "ack sends an ack to the channel" do
10
- expect(mock_channel).to receive(:ack).with("a_tag")
11
-
12
- message.ack
13
-
14
- expect(message.status).to eql(:acked)
15
- end
16
-
17
- it "retry sends a reject to the channel with requeue set" do
18
- expect(mock_channel).to receive(:reject).with("a_tag", true)
19
-
20
- message.retry
21
-
22
- expect(message.status).to eql(:retried)
23
- end
24
-
25
- it "reject sends a reject to the channel without requeue set" do
26
- expect(mock_channel).to receive(:reject).with("a_tag", false)
27
-
28
- message.discard
29
-
30
- expect(message.status).to eql(:discarded)
31
- end
32
- end
@@ -1,43 +0,0 @@
1
- require_relative 'spec_helper'
2
- require_relative '../lib/govuk_message_queue_consumer/test_helpers/mock_message'
3
-
4
- describe GovukMessageQueueConsumer::MockMessage do
5
- describe '#methods' do
6
- it "implements the same methods as Message" do
7
- mock = MockMessage.new
8
- real = Message.new(double, double, double)
9
-
10
- expect(real.methods - mock.methods).to be_empty
11
- end
12
- end
13
-
14
- describe '#ack' do
15
- it "marks the message as acked" do
16
- message = MockMessage.new
17
-
18
- message.ack
19
-
20
- expect(message).to be_acked
21
- end
22
- end
23
-
24
- describe '#retry' do
25
- it "marks the message as retried" do
26
- message = MockMessage.new
27
-
28
- message.retry
29
-
30
- expect(message).to be_retried
31
- end
32
- end
33
-
34
- describe '#discard' do
35
- it "marks the message as discarded" do
36
- message = MockMessage.new
37
-
38
- message.discard
39
-
40
- expect(message).to be_discarded
41
- end
42
- end
43
- end
@@ -1,26 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe RabbitMQConfig do
4
- describe ".from_environment" do
5
- it "connects to rabbitmq with the correct environment variables" do
6
- ENV["RABBITMQ_HOSTS"] = "server-one,server-two"
7
- ENV["RABBITMQ_VHOST"] = "/"
8
- ENV["RABBITMQ_USER"] = "my_user"
9
- ENV["RABBITMQ_PASSWORD"] = "my_pass"
10
-
11
- expect(RabbitMQConfig.new.from_environment).to eql({
12
- hosts: ["server-one", "server-two"],
13
- vhost: "/",
14
- user: "my_user",
15
- pass: "my_pass",
16
- recover_from_connection_close: true,
17
- })
18
- end
19
-
20
- it "provides a friendly error message when a variable is missing" do
21
- ENV["RABBITMQ_HOSTS"] = nil
22
-
23
- expect { RabbitMQConfig.new.from_environment }.to raise_error(RabbitMQConfig::ConfigurationError)
24
- end
25
- end
26
- end
data/spec/spec_helper.rb DELETED
@@ -1,16 +0,0 @@
1
- require_relative '../lib/govuk_message_queue_consumer'
2
-
3
- include GovukMessageQueueConsumer
4
-
5
- module TestHelpers
6
- def stub_environment_variables!
7
- ENV["RABBITMQ_HOSTS"] ||= ""
8
- ENV["RABBITMQ_VHOST"] ||= "/"
9
- ENV["RABBITMQ_USER"] ||= "/"
10
- ENV["RABBITMQ_PASSWORD"] ||= "/"
11
- end
12
- end
13
-
14
- RSpec.configure do |c|
15
- c.include TestHelpers
16
- end