Skip to content

Commit

Permalink
Reorganize spec/support files (#3340)
Browse files Browse the repository at this point in the history
* Move custom matchers to a single folder

* Remove unneeded .keep files

* Remove requires for spec_helper as its included by .rspec default

* Remove additional matcher requires
  • Loading branch information
kfrz authored Oct 2, 2019
1 parent f9aa935 commit e562b3f
Show file tree
Hide file tree
Showing 27 changed files with 31 additions and 44 deletions.
Empty file removed app/controllers/concerns/.keep
Empty file.
Empty file removed app/mailers/.keep
Empty file.
1 change: 0 additions & 1 deletion app/models/.keep

This file was deleted.

Empty file removed app/models/concerns/.keep
Empty file.
Empty file removed lib/assets/.keep
Empty file.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require 'rails_helper'
require 'support/attr_encrypted_matcher'

RSpec.describe ClaimsApi::AutoEstablishedClaim, type: :model do
let(:auto_form) { build(:auto_established_claim, auth_headers: { some: 'data' }) }
Expand Down
1 change: 0 additions & 1 deletion modules/claims_api/spec/models/power_of_attorney_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require 'rails_helper'
require 'support/attr_encrypted_matcher'

RSpec.describe ClaimsApi::PowerOfAttorney, type: :model do
let(:pending_record) { create(:power_of_attorney) }
Expand Down
1 change: 0 additions & 1 deletion modules/claims_api/spec/models/supporting_document_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require 'rails_helper'
require 'support/attr_encrypted_matcher'

RSpec.describe ClaimsApi::SupportingDocument, type: :model do
describe 'encrypted attribute' do
Expand Down
1 change: 0 additions & 1 deletion spec/feature/.keep

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'
require 'common/exceptions'

describe Common::Exceptions::SchemaValidationErrors do
Expand Down
1 change: 0 additions & 1 deletion spec/lib/hca/enrollment_system_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require 'rails_helper'
require 'spec_helper'
require 'hca/enrollment_system'

describe HCA::EnrollmentSystem do
Expand Down
1 change: 0 additions & 1 deletion spec/lib/hca/validations_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'
require 'hca/validations'

frozen_time = '2017-01-04 03:00:00 EDT'
Expand Down
1 change: 0 additions & 1 deletion spec/models/.keep

This file was deleted.

1 change: 0 additions & 1 deletion spec/models/form_profile_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require 'rails_helper'
require 'support/attr_encrypted_matcher'

RSpec.describe FormProfile, type: :model do
include SchemaMatchers
Expand Down
1 change: 0 additions & 1 deletion spec/models/in_progress_form_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require 'rails_helper'
require 'support/attr_encrypted_matcher'

RSpec.describe InProgressForm, type: :model do
let(:in_progress_form) { build(:in_progress_form) }
Expand Down
2 changes: 0 additions & 2 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
require File.expand_path('../config/environment', __dir__)
# Prevent database truncation if the environment is production
abort('The Rails environment is running in production mode!') if Rails.env.production?
require 'spec_helper'
require 'statsd-instrument'
require 'statsd/instrument/matchers'
require 'rspec/rails'
require 'webmock/rspec'
require 'support/factory_bot'
require 'support/serializer_spec_helper'
require 'support/xml_matchers'
require 'support/validation_helpers'
require 'support/model_helpers'
require 'support/authenticated_session_helper'
Expand Down
26 changes: 0 additions & 26 deletions spec/request/authentication/standard_authentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,6 @@

private

RSpec::Matchers.define :match_episode_body do |expected|
match do |actual|
actual == expected
end

failure_message do |actual|
message = "expected that #{actual} would match #{expected}"
outputs = [actual, expected].map { |a| pretty(a) }
message += "\nDiff:" + differ.diff_as_string(*outputs)
message
end

def pretty(output)
JSON.pretty_generate(JSON.parse(output))
rescue
output
end

def differ
RSpec::Support::Differ.new(
object_preparer: ->(object) { RSpec::Matchers::Composable.surface_descriptions_in(object) },
color: RSpec::Matchers.configuration.color?
)
end
end

def make_request(episode)
params = if episode.method == 'post'
Rack::Utils.parse_nested_query(episode.body['string'])
Expand Down
6 changes: 1 addition & 5 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
require 'fakeredis/rspec'
require 'support/mvi/stub_mvi'
require 'support/spec_builders'
require 'support/schema_matchers'
require 'support/matchers'
require 'support/spool_helpers'
require 'support/fixture_helpers'
require 'support/spec_temp_files'
require 'support/have_deep_attributes_matcher'
require 'support/be_a_uuid'
require 'support/impl_matchers'
require 'support/negated_matchers'
require 'support/sidekiq/batch'
require 'support/stub_emis'
require 'support/stub_evss_pciu'
Expand Down
3 changes: 3 additions & 0 deletions spec/support/matchers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

Dir[File.join(__dir__, 'matchers', '*.rb')].each { |file| require file }
File renamed without changes.
File renamed without changes.
27 changes: 27 additions & 0 deletions spec/support/matchers/episode_body_matcher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

RSpec::Matchers.define :match_episode_body do |expected|
match do |actual|
actual == expected
end

failure_message do |actual|
message = "expected that #{actual} would match #{expected}"
outputs = [actual, expected].map { |a| pretty(a) }
message += "\nDiff:" + differ.diff_as_string(*outputs)
message
end

def pretty(output)
JSON.pretty_generate(JSON.parse(output))
rescue
output
end

def differ
RSpec::Support::Differ.new(
object_preparer: ->(object) { RSpec::Matchers::Composable.surface_descriptions_in(object) },
color: RSpec::Matchers.configuration.color?
)
end
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit e562b3f

Please sign in to comment.