From ff41e5b9eb18a2a54d41e8dc81c488c276eb2f6d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 27 Jun 2024 01:48:00 +0000 Subject: [PATCH 1/3] Update rubocop-govuk requirement from = 4.18.0 to = 5.0.1 Updates the requirements on [rubocop-govuk](https://github.com/alphagov/rubocop-govuk) to permit the latest version. - [Changelog](https://github.com/alphagov/rubocop-govuk/blob/main/CHANGELOG.md) - [Commits](https://github.com/alphagov/rubocop-govuk/compare/v4.18.0...v5.0.1) --- updated-dependencies: - dependency-name: rubocop-govuk dependency-type: direct:development ... Signed-off-by: dependabot[bot] --- govuk_message_queue_consumer.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/govuk_message_queue_consumer.gemspec b/govuk_message_queue_consumer.gemspec index dd37e15..035f3e5 100644 --- a/govuk_message_queue_consumer.gemspec +++ b/govuk_message_queue_consumer.gemspec @@ -22,6 +22,6 @@ Gem::Specification.new do |s| s.add_development_dependency "pry-byebug" s.add_development_dependency "rake" s.add_development_dependency "rspec", "~> 3.11" - s.add_development_dependency "rubocop-govuk", "4.18.0" + s.add_development_dependency "rubocop-govuk", "5.0.1" s.add_development_dependency "yard" end From c949d46ac5c75ff2abf272ea0e6e05d18c1df3f5 Mon Sep 17 00:00:00 2001 From: Bruce Bolt Date: Thu, 27 Jun 2024 10:32:24 +0100 Subject: [PATCH 2/3] Auto-correct rubocop failures --- spec/govuk_message_queue_consumer/consumer_spec.rb | 4 ++-- .../heartbeat_processor_spec.rb | 8 ++++---- spec/govuk_message_queue_consumer/message_spec.rb | 6 +++--- .../test_helpers/mock_message_spec.rb | 2 +- spec/support/queue_helpers.rb | 6 +++--- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/spec/govuk_message_queue_consumer/consumer_spec.rb b/spec/govuk_message_queue_consumer/consumer_spec.rb index c2da5c4..0781db2 100644 --- a/spec/govuk_message_queue_consumer/consumer_spec.rb +++ b/spec/govuk_message_queue_consumer/consumer_spec.rb @@ -4,8 +4,8 @@ describe GovukMessageQueueConsumer::Consumer do include QueueHelpers - let(:logger) { instance_double("Logger") } - let(:client_processor) { instance_double("Client::Processor") } + let(:logger) { instance_double(Logger) } + let(:client_processor) { instance_double(Client::Processor) } describe "#run" do let(:stubs) { create_bunny_stubs } diff --git a/spec/govuk_message_queue_consumer/heartbeat_processor_spec.rb b/spec/govuk_message_queue_consumer/heartbeat_processor_spec.rb index e9fef2a..97589e7 100644 --- a/spec/govuk_message_queue_consumer/heartbeat_processor_spec.rb +++ b/spec/govuk_message_queue_consumer/heartbeat_processor_spec.rb @@ -1,10 +1,10 @@ require "spec_helper" describe GovukMessageQueueConsumer::HeartbeatProcessor do - let(:heartbeat_headers) { instance_double("Heartbeat Headers", content_type: "application/x-heartbeat") } - let(:heartbeat_message) { instance_double("Heartbeat Message", headers: heartbeat_headers, ack: nil) } - let(:standard_headers) { instance_double("Standard Headers", content_type: nil) } - let(:standard_message) { instance_double("Standard Message", headers: standard_headers, ack: nil) } + let(:heartbeat_headers) { instance_double(Heartbeat(Headers, content_type: "application/x-heartbeat")) } + let(:heartbeat_message) { instance_double(Heartbeat(Message, headers: heartbeat_headers, ack: nil)) } + let(:standard_headers) { instance_double(Standard(Headers, content_type: nil)) } + let(:standard_message) { instance_double(Standard(Message, headers: standard_headers, ack: nil)) } context "when receiving heartbeat message" do it "doesn't call the next processor" do diff --git a/spec/govuk_message_queue_consumer/message_spec.rb b/spec/govuk_message_queue_consumer/message_spec.rb index 51b58ee..8cecbb7 100644 --- a/spec/govuk_message_queue_consumer/message_spec.rb +++ b/spec/govuk_message_queue_consumer/message_spec.rb @@ -1,9 +1,9 @@ require "spec_helper" describe GovukMessageQueueConsumer::Message do - let(:mock_channel) { instance_double("Channel") } - let(:delivery_info) { instance_double("DeliveryInfo", channel: mock_channel, delivery_tag: "a_tag") } - let(:headers) { instance_double("Headers") } + let(:mock_channel) { instance_double(Channel) } + let(:delivery_info) { instance_double(DeliveryInfo, channel: mock_channel, delivery_tag: "a_tag") } + let(:headers) { instance_double(Headers) } let(:message) { described_class.new({ "a" => "payload" }, headers, delivery_info) } it "ack sends an ack to the channel" do diff --git a/spec/govuk_message_queue_consumer/test_helpers/mock_message_spec.rb b/spec/govuk_message_queue_consumer/test_helpers/mock_message_spec.rb index 443444b..ae5e74c 100644 --- a/spec/govuk_message_queue_consumer/test_helpers/mock_message_spec.rb +++ b/spec/govuk_message_queue_consumer/test_helpers/mock_message_spec.rb @@ -1,7 +1,7 @@ require "spec_helper" require "govuk_message_queue_consumer/test_helpers" -describe GovukMessageQueueConsumer::MockMessage do # rubocop:disable RSpec/FilePath +describe GovukMessageQueueConsumer::MockMessage do # rubocop:disable RSpec/SpecFilePathFormat describe "#methods" do it "implements the same methods as Message" do mock = described_class.new diff --git a/spec/support/queue_helpers.rb b/spec/support/queue_helpers.rb index b702462..e169d6f 100644 --- a/spec/support/queue_helpers.rb +++ b/spec/support/queue_helpers.rb @@ -8,15 +8,15 @@ def create_bunny_stubs end def create_connection(channel) - instance_double("Bunny::Session", start: nil, create_channel: channel) + instance_double(Bunny::Session, start: nil, create_channel: channel) end def create_channel(queue) - instance_double("Bunny::Channel", queue:, prefetch: nil, topic: nil) + instance_double(Bunny::Channel, queue:, prefetch: nil, topic: nil) end def create_queue - instance_double("Bunny::Queue", bind: nil, subscribe: "") + instance_double(Bunny::Queue, bind: nil, subscribe: "") end class BunnyStubs From a33bd25f20514bdc9155f98c25739fdf0a726e19 Mon Sep 17 00:00:00 2001 From: Ynda Jas Date: Mon, 1 Jul 2024 12:22:43 +0100 Subject: [PATCH 3/3] Fix post-lint test errors Applying linter autofixes caused test errors. The issue here was that we were using `instance_double`s for external classes. Before the linter autofixes, the references to the external classes were just strings. To make both the linter happy and the tests functional, we can just use a regular `double` and then stub the messages we care about in a `before` block. We can't just do e.g. `double(message: return_value)` because of the `VerifiedDoubles` rule: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/VerifiedDoubles --- .../govuk_message_queue_consumer/consumer_spec.rb | 4 ++-- .../heartbeat_processor_spec.rb | 15 +++++++++++---- spec/govuk_message_queue_consumer/message_spec.rb | 10 +++++++--- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/spec/govuk_message_queue_consumer/consumer_spec.rb b/spec/govuk_message_queue_consumer/consumer_spec.rb index 0781db2..02a5d4e 100644 --- a/spec/govuk_message_queue_consumer/consumer_spec.rb +++ b/spec/govuk_message_queue_consumer/consumer_spec.rb @@ -4,8 +4,8 @@ describe GovukMessageQueueConsumer::Consumer do include QueueHelpers - let(:logger) { instance_double(Logger) } - let(:client_processor) { instance_double(Client::Processor) } + let(:logger) { double } + let(:client_processor) { double } describe "#run" do let(:stubs) { create_bunny_stubs } diff --git a/spec/govuk_message_queue_consumer/heartbeat_processor_spec.rb b/spec/govuk_message_queue_consumer/heartbeat_processor_spec.rb index 97589e7..9e62fa6 100644 --- a/spec/govuk_message_queue_consumer/heartbeat_processor_spec.rb +++ b/spec/govuk_message_queue_consumer/heartbeat_processor_spec.rb @@ -1,10 +1,17 @@ require "spec_helper" describe GovukMessageQueueConsumer::HeartbeatProcessor do - let(:heartbeat_headers) { instance_double(Heartbeat(Headers, content_type: "application/x-heartbeat")) } - let(:heartbeat_message) { instance_double(Heartbeat(Message, headers: heartbeat_headers, ack: nil)) } - let(:standard_headers) { instance_double(Standard(Headers, content_type: nil)) } - let(:standard_message) { instance_double(Standard(Message, headers: standard_headers, ack: nil)) } + let(:heartbeat_headers) { double } + let(:heartbeat_message) { double } + let(:standard_headers) { double } + let(:standard_message) { double } + + before do + allow(heartbeat_headers).to receive(:content_type).and_return("application/x-heartbeat") + allow(heartbeat_message).to receive_messages(headers: heartbeat_headers, ack: nil) + allow(standard_headers).to receive(:content_type).and_return(nil) + allow(standard_message).to receive_messages(headers: standard_headers, ack: nil) + end context "when receiving heartbeat message" do it "doesn't call the next processor" do diff --git a/spec/govuk_message_queue_consumer/message_spec.rb b/spec/govuk_message_queue_consumer/message_spec.rb index 8cecbb7..fd5a6a7 100644 --- a/spec/govuk_message_queue_consumer/message_spec.rb +++ b/spec/govuk_message_queue_consumer/message_spec.rb @@ -1,11 +1,15 @@ require "spec_helper" describe GovukMessageQueueConsumer::Message do - let(:mock_channel) { instance_double(Channel) } - let(:delivery_info) { instance_double(DeliveryInfo, channel: mock_channel, delivery_tag: "a_tag") } - let(:headers) { instance_double(Headers) } + let(:mock_channel) { double } + let(:delivery_info) { double } + let(:headers) { double } let(:message) { described_class.new({ "a" => "payload" }, headers, delivery_info) } + before do + allow(delivery_info).to receive_messages(channel: mock_channel, delivery_tag: "a_tag") + end + it "ack sends an ack to the channel" do expect(mock_channel).to receive(:ack).with("a_tag")