Skip to content

Commit

Permalink
Rubocop rspec fixes round 1 (#3348)
Browse files Browse the repository at this point in the history
* Fixing Rubocop Rspec FactoryBot/CreateList offenses.

* Fixing Rubocop Rspec RSpec/BeEql offenses.

* Fixing Rubocop RSpec/EmptyLineAfterExampleGroup offenses.

* Fixing Rubocop RSpec/LetBeforeExamples offenses.

* Removing comments from .rubocop_todo.yml.
  • Loading branch information
thilton-oddball authored Sep 27, 2019
1 parent eb0a9e3 commit 6acbed8
Show file tree
Hide file tree
Showing 25 changed files with 68 additions and 90 deletions.
46 changes: 0 additions & 46 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@
FactoryBot/AttributeDefinedStatically:
Enabled: false

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: create_list, n_times
FactoryBot/CreateList:
Exclude:
- 'spec/jobs/education_form/create_daily_fiscal_year_to_date_report_spec.rb'
- 'spec/jobs/education_form/create_daily_year_to_date_report_spec.rb'

# Offense count: 250
RSpec/AnyInstance:
Enabled: false
Expand All @@ -30,12 +21,6 @@ RSpec/Be:
- 'spec/lib/common/client/concerns/monitoring_spec.rb'
- 'spec/request/id_card_attributes_request_spec.rb'

# Offense count: 1
# Cop supports --auto-correct.
RSpec/BeEql:
Exclude:
- 'spec/lib/sentry/processor/filter_request_body_spec.rb'

# Offense count: 28
RSpec/BeforeAfterAll:
Enabled: false
Expand Down Expand Up @@ -75,26 +60,6 @@ RSpec/EmptyExampleGroup:
- 'spec/lib/sentry/processor/log_as_warning_processor_spec.rb'
- 'spec/models/form_profile_spec.rb'

# Offense count: 35
# Cop supports --auto-correct.
RSpec/EmptyLineAfterExampleGroup:
Exclude:
- 'modules/claims_api/spec/models/auto_establish_claim_spec.rb'
- 'modules/claims_api/spec/models/power_of_attorney_spec.rb'
- 'spec/controllers/v0/post_911_gi_bill_statuses_controller_spec.rb'
- 'spec/jobs/education_form/education_facility_spec.rb'
- 'spec/jobs/transactional_email_analytics_job_spec.rb'
- 'spec/lib/common/models/redis_store_spec.rb'
- 'spec/lib/hca/service_spec.rb'
- 'spec/lib/mvi/configuration_spec.rb'
- 'spec/lib/mvi/messages/message_builder_spec.rb'
- 'spec/lib/pdf_fill/forms/va214142_spec.rb'
- 'spec/lib/saml/saml_settings_service_spec.rb'
- 'spec/lib/sentry_logging_spec_helper.rb'
- 'spec/models/mvi_spec.rb'
- 'spec/models/okta_redis/grants_spec.rb'
- 'spec/uploaders/evss_claim_document_uploader_spec.rb'

# Offense count: 229
# Cop supports --auto-correct.
RSpec/EmptyLineAfterFinalLet:
Expand Down Expand Up @@ -189,17 +154,6 @@ RSpec/LeadingSubject:
RSpec/LeakyConstantDeclaration:
Enabled: false

# Offense count: 10
# Cop supports --auto-correct.
RSpec/LetBeforeExamples:
Exclude:
- 'spec/controllers/v0/gi_bill_feedbacks_controller_spec.rb'
- 'spec/controllers/v0/vic/vic_submissions_controller_spec.rb'
- 'spec/lib/mhv_ac/client_spec.rb'
- 'spec/rakelib/vet360_spec.rb'
- 'spec/request/health_records_request_spec.rb'
- 'spec/serializers/evss_claim_detail_serializer_spec.rb'

# Offense count: 25
RSpec/LetSetup:
Exclude:
Expand Down
2 changes: 2 additions & 0 deletions modules/claims_api/spec/models/auto_establish_claim_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
expect(described_class.pending?('123')).to be(false)
end
end

context 'with pending records' do
it 'should truthy and return the record' do
result = described_class.pending?(pending_record.id)
Expand All @@ -42,6 +43,7 @@
expect(described_class.evss_id_by_token('thisisntatoken')).to be(nil)
end
end

context 'with record without evss id' do
it 'should return nil' do
expect(described_class.evss_id_by_token(pending_record.token)).to be(nil)
Expand Down
1 change: 1 addition & 0 deletions modules/claims_api/spec/models/power_of_attorney_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
expect(described_class.pending?('123')).to be(false)
end
end

context 'with pending records' do
it 'should truthy and return the record' do
result = described_class.pending?(pending_record.id)
Expand Down
5 changes: 2 additions & 3 deletions spec/controllers/v0/gi_bill_feedbacks_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
require 'support/controller_spec_helper'

RSpec.describe V0::GIBillFeedbacksController, type: :controller do
let(:form) { build(:gi_bill_feedback).form }
let(:user) { create(:user) }
it_should_behave_like 'a controller that deletes an InProgressForm',
'gi_bill_feedback', 'gi_bill_feedback', GIBillFeedback::FORM_ID

def parsed_body
JSON.parse(response.body)
end

let(:user) { create(:user) }
let(:form) { build(:gi_bill_feedback).form }

describe '#create' do
def send_create
post(:create, params: { gi_bill_feedback: { form: form } })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
.and trigger_statsd_increment(described_class::STATSD_GI_BILL_TOTAL_KEY, **once)
end
end

describe 'when EVSS has no info of user' do
# special EVSS CI user ssn=796066622
let(:user) { FactoryBot.create(:user, :loa3, ssn: '796066622', uuid: '89b40886-95e3-4a5b-824e-a4658b707508') }
Expand Down
5 changes: 2 additions & 3 deletions spec/controllers/v0/vic/vic_submissions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
require 'support/controller_spec_helper'

RSpec.describe V0::VIC::VICSubmissionsController, type: :controller do
it_should_behave_like 'a controller that deletes an InProgressForm', 'vic_submission', 'vic_submission', 'VIC'

let(:user) { create(:user) }
let(:form) { build(:vic_submission).form }
let(:user) { create(:user) }
it_should_behave_like 'a controller that deletes an InProgressForm', 'vic_submission', 'vic_submission', 'VIC'

describe '#create' do
def send_create
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ def get_education_form_fixture(filename)

context 'with some sample submissions', run_at: '2017-01-04 03:00:00 EDT' do
before do
2.times do
create(:education_benefits_submission, status: :processed, created_at: date)
end
create_list(:education_benefits_submission, 2, status: :processed, created_at: date)

create(
:education_benefits_submission,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ def get_education_form_fixture(filename)

context 'with some sample submissions', run_at: '2017-01-04 03:00:00 EDT' do
before do
2.times do
create(:education_benefits_submission, status: :processed, created_at: date)
end
create_list(:education_benefits_submission, 2, status: :processed, created_at: date)

create(
:education_benefits_submission,
Expand Down
7 changes: 7 additions & 0 deletions spec/jobs/education_form/education_facility_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def school(data)
expect(described_class.routing_address(form, form_type: '1990').state).to eq(western_address.state)
end
end

context '22-1990N' do
let(:form) { OpenStruct.new(veteranAddress: western_address) }
it 'uses educationProgram over veteranAddress' do
Expand All @@ -41,6 +42,7 @@ def school(data)
expect(described_class.routing_address(form, form_type: '1990n').state).to eq(western_address.state)
end
end

context '22-1995' do
let(:form) { OpenStruct.new(veteranAddress: western_address) }
it 'uses newSchool over relativeAddress' do
Expand All @@ -51,6 +53,7 @@ def school(data)
expect(described_class.routing_address(form, form_type: '1995').state).to eq(western_address.state)
end
end

%w[1990E 5490 5495].each do |form_type|
context "22-#{form_type}" do
let(:form) { OpenStruct.new(relativeAddress: western_address) }
Expand Down Expand Up @@ -120,6 +123,7 @@ def school(data)
expect(described_class.region_for(education_benefits_claim)).to eq(:eastern)
end
end

context '22-1995S' do
it 'should route to Eastern RPO' do
form = education_benefits_claim.parsed_form
Expand All @@ -139,18 +143,21 @@ def school(data)
expect(described_class.region_for(education_benefits_claim)).to eq(:eastern)
end
end

context '22-0994' do
it 'should route to Eastern RPO' do
education_benefits_claim.saved_claim.form_id = '22-0994'
expect(described_class.region_for(education_benefits_claim)).to eq(:eastern)
end
end

context '22-0993' do
it 'should route to Western RPO' do
education_benefits_claim.saved_claim.form_id = '22-0993'
expect(described_class.region_for(education_benefits_claim)).to eq(:western)
end
end

context 'address country Phillipines' do
it 'should route to Western RPO' do
form = education_benefits_claim.parsed_form
Expand Down
2 changes: 2 additions & 0 deletions spec/jobs/transactional_email_analytics_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@
expect(subject.send(:we_should_break?)).to be false
end
end

context 'last email created_at < time-range start time' do
it 'should return true' do
@emails.collection.last.attributes[:created_at] = 25.hours.ago.to_s
expect(subject.send(:we_should_break?)).to be true
end
end

context 'less than 50 emails were returned by govdelivery' do
it 'should return true' do
@emails.collection.delete_at(0)
Expand Down
1 change: 1 addition & 0 deletions spec/lib/common/models/redis_store_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
expect(klass.exists?('e66fd7b7-94e0-4748-8063-283f55efb0ea')).to be_truthy
end
end

context 'when the model is saved' do
it 'returns false' do
expect(klass.exists?('e66fd7b7-94e0-4748-8063-283f55efb0ea')).to be_falsey
Expand Down
1 change: 1 addition & 0 deletions spec/lib/hca/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
)
end
end

context 'when there are SSL options' do
it 'should return the wsdl, cert and key paths' do
expect(HCA::Configuration.instance.ssl_options).to eq(
Expand Down
31 changes: 14 additions & 17 deletions spec/lib/mhv_ac/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,13 @@
# bundle exec rake mvi:find first_name="Hector" middle_name="J" last_name="Allen" _
# birth_date="1932-02-05" gender="M" ssn="796126859"

it 'fetches a list of states', :vcr do
client_response = client.get_states
expect(client_response).to be_a(Hash)
end

it 'fetches a list of countries', :vcr do
client_response = client.get_countries
expect(client_response).to be_a(Hash)
let(:upgrade_params) do
{
user_id: '14221465',
form_signed_date_time: time.httpdate,
terms_version: 'v3.4'
}
end

let(:time) { Time.parse('Tue, 09 May 2017 00:00:00 GMT').utc }

let(:user_params) do
{
icn: '1012667122V019349',
Expand All @@ -42,13 +37,15 @@
terms_version: 'v3.2'
}
end
let(:time) { Time.parse('Tue, 09 May 2017 00:00:00 GMT').utc }
it 'fetches a list of states', :vcr do
client_response = client.get_states
expect(client_response).to be_a(Hash)
end

let(:upgrade_params) do
{
user_id: '14221465',
form_signed_date_time: time.httpdate,
terms_version: 'v3.4'
}
it 'fetches a list of countries', :vcr do
client_response = client.get_countries
expect(client_response).to be_a(Hash)
end

it 'creates an account', :vcr do
Expand Down
1 change: 1 addition & 0 deletions spec/lib/mvi/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
expect(MVI::Configuration.instance.ssl_options).to be_nil
end
end

context 'when there are SSL options' do
let(:cert) { instance_double('OpenSSL::X509::Certificate') }
let(:key) { instance_double('OpenSSL::PKey::RSA') }
Expand Down
1 change: 1 addition & 0 deletions spec/lib/mvi/messages/message_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
end
end
end

context 'in production environments' do
it 'has a processing code node of P' do
with_settings(Settings.mvi, processing_code: 'P') do
Expand Down
1 change: 1 addition & 0 deletions spec/lib/pdf_fill/forms/va214142_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def class_form_data
)
end
end

context 'va file number is blank' do
let(:form_data) do
{}
Expand Down
2 changes: 2 additions & 0 deletions spec/lib/saml/saml_settings_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
.to eq('urn:oasis:names:tc:SAML:2.0:nameid-format:persistent')
end
end

context 'with metadata 500 responses' do
before do
stub_request(:get, Settings.saml.metadata_url).to_return(
Expand All @@ -44,6 +45,7 @@
expect(a_request(:get, Settings.saml.metadata_url)).to have_been_made.times(9)
end
end

context 'when a parsing error occurs' do
it 'should log and reraise the error' do
stub_request(:get, Settings.saml.metadata_url).to_return(status: 200, body: '<xml></')
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/sentry/processor/filter_request_body_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
}
result = @processor.process(sentry_request)

expect(result['request']['data']).to eql(nil)
expect(result['request']['data']).to be(nil)
end
end

Expand Down
2 changes: 2 additions & 0 deletions spec/lib/sentry_logging_spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
subject.log_message_to_sentry('blah', :error, { extra: 'context' }, tags: 'tagging')
end
end

describe '#log_exception_to_sentry' do
it 'warn logs to Rails logger' do
expect(Rails.logger).to receive(:error).with(exception.message + '.')
Expand All @@ -47,6 +48,7 @@
subject.log_message_to_sentry('blah', :warn, { extra: 'context' }, tags: 'tagging')
end
end

describe '#log_exception_to_sentry' do
it 'error logs to Rails logger' do
expect(Rails.logger).to receive(:error).with(exception.message + '.')
Expand Down
Loading

0 comments on commit 6acbed8

Please sign in to comment.