Skip to content

Commit

Permalink
Merge pull request #6075 from ministryofjustice/rubocop/address-verif…
Browse files Browse the repository at this point in the history
…ied-doubles

Rubocop: Remove verified doubles violations
  • Loading branch information
colinbruce authored Dec 4, 2023
2 parents 3bfe529 + c85ecf7 commit aff1901
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 51 deletions.
10 changes: 0 additions & 10 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,3 @@ RSpec/StubbedMock:
- 'spec/services/digest_exporter_spec.rb'
- 'spec/services/govuk_emails/delivery_man_spec.rb'
- 'spec/services/metrics/send_metrics_spec.rb'

# Offense count: 12
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
RSpec/VerifiedDoubles:
Exclude:
- 'spec/lib/slack_alerter_spec.rb'
- 'spec/services/ccms/attribute_value_generator_spec.rb'
- 'spec/services/govuk_emails/delivery_man_spec.rb'
- 'spec/services/malware_scanner_spec.rb'
- 'spec/support/shared_context/ccms_soa_configuration_context.rb'
4 changes: 0 additions & 4 deletions app/services/ccms/attribute_value_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class AttributeValueGenerator
|savings_amount
|income_type
|vehicle
|wage_slip
)_(\S+)$}x
APPLICANT_REGEX = /^applicant_(\S+)$/
PARTNER_REGEX = /^partner_(\S+)$/
Expand All @@ -57,7 +56,6 @@ class AttributeValueGenerator
SAVINGS_AMOUNT = /^savings_amount_(\S+)$/
INCOME_TYPE_REGEX = /^income_type_(\S+)$/
VEHICLE_REGEX = /^vehicle_(\S+)$/
WAGE_SLIP_REGEX = /^wage_slip_(\S+)$/
OUTGOING = /^outgoing_(\S+)$/

PROSPECTS_OF_SUCCESS = {
Expand Down Expand Up @@ -443,8 +441,6 @@ def call_standard_method(method, options)
options[:dependant].__send__(Regexp.last_match(1))
when VEHICLE_REGEX
options[:vehicle].__send__(Regexp.last_match(1))
when WAGE_SLIP_REGEX
options[:wage_slip].__send__(Regexp.last_match(1))
when PROCEEDING_REGEX
options[:proceeding].__send__(Regexp.last_match(1))
when INCOME_TYPE_REGEX
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/slack_alerter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

before { allow(HostEnv).to receive(:environment).and_return(:uat) }

let(:dummy_mail) { double ExceptionAlertMailer }
let(:dummy_mail) { instance_double ActionMailer::MessageDelivery }
let(:dummy_email_address) { "[email protected]" }

describe ".capture_message" do
Expand Down
28 changes: 8 additions & 20 deletions spec/services/ccms/attribute_value_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module CCMS
describe "#method_missing" do
context "with a standardly_named_method" do
describe "bank account" do
let(:my_account) { double BankAccount }
let(:my_account) { instance_double BankAccount }
let(:options) { { bank_acct: my_account } }
let(:bank_account_name) { "MY ACCOUNT" }

Expand All @@ -20,31 +20,19 @@ module CCMS
end

describe "vehicle" do
let(:my_vehicle) { double "Vehicle" }
let(:my_vehicle) { instance_double Vehicle }
let(:options) { { vehicle: my_vehicle } }
let(:my_regno) { "AB12CDE" }
let(:my_estimated_value) { 1000.00 }

it "calls the #regno method on options[:vehicle]" do
expect(my_vehicle).to receive(:regno).and_return(my_regno)
regno = value_generator.vehicle_regno(options)
expect(regno).to eq my_regno
end
end

describe "wage_slip" do
let(:my_wage_slip) { double "WageSlip" }
let(:options) { { wage_slip: my_wage_slip } }
let(:my_ni_contribution) { 34.78 }

it "calls the #ni_contribution method on options[:wage_slip]" do
expect(my_wage_slip).to receive(:ni_contribution).and_return(my_ni_contribution)
ni_contribution = value_generator.wage_slip_ni_contribution(options)
expect(ni_contribution).to eq my_ni_contribution
expect(my_vehicle).to receive(:estimated_value).and_return(my_estimated_value)
estimated_value = value_generator.vehicle_estimated_value(options)
expect(estimated_value).to eq my_estimated_value
end
end

describe "proceeding" do
let(:my_proceeding) { double Proceeding }
let(:my_proceeding) { instance_double Proceeding }
let(:options) { { proceeding: my_proceeding } }
let(:my_name) { "Non-mol" }

Expand All @@ -67,7 +55,7 @@ module CCMS

describe "#respond_to?" do
context "with standardly_named methods" do
let(:my_account) { double BankAccount, name: "MY ACCOUNT" }
let(:my_account) { instance_double BankAccount, name: "MY ACCOUNT" }
let(:options) { { bank_acct: my_account } }

context "and a valid method on delegated object" do
Expand Down
13 changes: 7 additions & 6 deletions spec/services/govuk_emails/delivery_man_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,24 @@

context "when the mail is still waiting" do
context "and mail is eligible for delivery" do
let(:message) { double "MailMessage", govuk_notify_response: govuk_response }
let(:govuk_response) { double "GovukResponse", id: govuk_message_id }
let(:message) { instance_double ActionMailer::MessageDelivery }
let(:response) { instance_double Mail::Message, govuk_notify_response: govuk_response }
let(:govuk_response) { instance_double Notifications::Client::ResponseNotification, id: govuk_message_id }
let(:govuk_message_id) { SecureRandom.uuid }
let(:time_now) { Time.current }

before { allow(mailer_klass.constantize).to receive(:eligible_for_delivery?).and_return(true) }

it "delivers the mail" do
expect(mailer_klass.constantize).to receive(mailer_method).and_return(message)
expect(message).to receive(:deliver_now!).and_return(message)
expect(message).to receive(:deliver_now!).and_return(response)
delivery_man
end

it "updates the scheduled mail record" do
travel_to time_now
allow(mailer_klass.constantize).to receive(mailer_method).and_return(message)
allow(message).to receive(:deliver_now!).and_return(message)
allow(message).to receive(:deliver_now!).and_return(response)
delivery_man

scheduled_mailing.reload
Expand Down Expand Up @@ -94,8 +95,8 @@
end

context "when the mail raises an exception" do
let(:message) { double "MailMessage", govuk_notify_response: govuk_response }
let(:govuk_response) { double "GovukResponse", id: govuk_message_id }
let(:message) { instance_double ActionMailer::MessageDelivery, govuk_notify_response: govuk_response }
let(:govuk_response) { instance_double Notifications::Client::ResponseNotification, id: govuk_message_id }
let(:govuk_message_id) { SecureRandom.uuid }
let(:time_now) { Time.current }

Expand Down
2 changes: 1 addition & 1 deletion spec/services/malware_scanner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
end

context "when scanner is down" do
let(:scan_result) { ["failed: No such file or directory. ERROR\n", "", double("process_status", exitstatus: 2, success?: false)] }
let(:scan_result) { ["failed: No such file or directory. ERROR\n", "", instance_double(Process::Status, exitstatus: 2, success?: false)] }

before { allow(Open3).to receive(:capture3).and_return(scan_result) }

Expand Down
17 changes: 8 additions & 9 deletions spec/support/shared_context/ccms_soa_configuration_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@

RSpec.shared_context "with ccms soa configuration", shared_context: :metadata do
before do
allow(Rails.configuration.x).to receive(:ccms_soa).and_return(
double(
"CCMS SOA Config",
client_username: "my_soap_client_username",
client_password_type: "password_type",
client_password: "xxxxx",
user_login: "my_login",
user_role: "my_role",
),
ccms_struct = Struct.new(:client_username, :client_password_type, :client_password, :user_login, :user_role)
test_config = ccms_struct.new(
client_username: "my_soap_client_username",
client_password_type: "password_type",
client_password: "xxxxx",
user_login: "my_login",
user_role: "my_role",
)
allow(Rails.configuration.x).to receive(:ccms_soa).and_return(test_config)
end
end

0 comments on commit aff1901

Please sign in to comment.