specs: always require rails_helper

Test helpers are separated between two files: spec_helper and
rails_helper. This separation is meant to allow tests that do not
require Rails (like testing standalone libs) to boot faster.

The spec_helper file is always loaded, through `--require spec_helper`
in the `.rspec` config file. When needed, the rails_helper file is
expected to be required manually.

This is fine, but:
- Many test files have a redundant `require 'spec_helper'` line;
- Many test files should require `rails_helper`, but don't.

Not requiring `rails_helper` will cause the Rails-concerned section of
the test environment not to be configured–which may cause subtle bugs
(like the test database not being properly initialized).

Moreover, Spring loads all the Rails files on preloading anyway. So the
gains from using only `spec_helper` are thin.

To streamline this process, this commit:
- Configures `.rspec` to require `rails_helper` by default;
- Remove all manual requires to spec_helper or rails_helper.

Reference: https://stackoverflow.com/questions/24145329/how-is-spec-rails-helper-rb-different-from-spec-spec-helper-rb-do-i-need-it
This commit is contained in:
Pierre de La Morinerie 2020-03-25 15:04:48 +01:00
parent d6f6a076dd
commit 4cb747fdb6
161 changed files with 23 additions and 336 deletions

2
.rspec
View file

@ -1,2 +1,2 @@
--color
--require spec_helper
--require rails_helper

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Admin::AssignsController, type: :controller do
let(:admin) { create(:administrateur) }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Admin::InstructeursController, type: :controller do
let(:admin) { create(:administrateur) }
let(:email_2) { 'plip@octo.com' }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Admin::MailTemplatesController, type: :controller do
let(:procedure) { create :procedure }
let(:initiated_mail) { Mails::InitiatedMail.default_for_procedure(procedure) }

View file

@ -1,4 +1,3 @@
require 'spec_helper'
require 'uri'
describe Admin::ProceduresController, type: :controller do

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Administrations::OmniauthCallbacksController, type: :controller do
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:administration]

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe API::V1::DossiersController do
let(:admin) { create(:administrateur) }
let(:token) { admin.renew_api_token }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe API::V2::GraphqlController do
let(:admin) { create(:administrateur) }
let(:token) { admin.renew_api_token }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe APIController, type: :controller do
describe 'valid_token_for_procedure?' do
let(:procedure) { create(:procedure) }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe ApplicationController, type: :controller do
describe 'before_action: set_raven_context' do
it 'is present' do

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe AttachmentsController, type: :controller do
let(:user) { create(:user) }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Champs::CarteController, type: :controller do
let(:user) { create(:user) }
let(:procedure) { create(:procedure, :published) }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Champs::DossierLinkController, type: :controller do
let(:user) { create(:user) }
let(:procedure) { create(:procedure, :published) }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Champs::SiretController, type: :controller do
let(:user) { create(:user) }
let(:procedure) { create(:procedure, :published) }

View file

@ -1,5 +1,3 @@
require 'rails_helper'
RSpec.describe ProcedureContextConcern, type: :controller do
class TestController < ActionController::Base
include ProcedureContextConcern

View file

@ -1,5 +1,3 @@
require 'rails_helper'
RSpec.describe Devise::StoreLocationExtension, type: :controller do
class TestController < ActionController::Base
include Devise::Controllers::StoreLocation

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Instructeurs::AvisController, type: :controller do
context 'with a instructeur signed in' do
render_views

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Instructeurs::DossiersController, type: :controller do
render_views

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Instructeurs::InstructeurController, type: :controller do
describe 'before actions: authenticate_instructeur!' do
it 'is present' do

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Instructeurs::ProceduresController, type: :controller do
describe "before_action: ensure_ownership!" do
it "is present" do

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Instructeurs::RechercheController, type: :controller do
let(:dossier) { create(:dossier, :en_construction) }
let(:dossier2) { create(:dossier, :en_construction, procedure: dossier.procedure) }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe InvitesController, type: :controller do
let(:dossier) { create(:dossier, :en_construction) }
let(:email) { 'plop@octo.com' }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe PingController, type: :controller do
describe 'GET #index' do
subject { get :index }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe RootController, type: :controller do
subject { get :index }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe StatsController, type: :controller do
describe "#last_four_months_hash" do
context "while a regular user is logged in" do

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe SupportController, type: :controller do
render_views

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Users::CommencerController, type: :controller do
let(:user) { create(:user) }
let(:published_procedure) { create(:procedure, :published) }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Users::ConfirmationsController, type: :controller do
let!(:user) { create(:user, :unconfirmed) }
let(:confirmation_token) { user.confirmation_token }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Users::DossiersController, type: :controller do
let(:user) { create(:user) }

View file

@ -1,5 +1,3 @@
require "spec_helper"
describe Users::PasswordsController, type: :controller do
before do
@request.env["devise.mapping"] = Devise.mappings[:user]

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Users::ProfilController, type: :controller do
include ActiveJob::TestHelper

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Users::UserController, type: :controller do
describe 'before actions: authenticate_instructeur!' do
it 'is present' do

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe WebhookController, type: :controller do
describe '#helpscout' do
before { allow(controller).to receive(:verify_signature!).and_return(true) }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
feature 'As an administrateur', js: true do
let(:administration) { create(:administration) }
let(:admin_email) { 'new_admin@gouv.fr' }

View file

@ -1,4 +1,3 @@
require 'spec_helper'
require 'features/admin/procedure_spec_helper'
feature 'As an administrateur I wanna clone a procedure', js: true do

View file

@ -1,4 +1,3 @@
require 'spec_helper'
require 'features/admin/procedure_spec_helper'
feature 'As an administrateur I wanna create a new procedure', js: true do

View file

@ -1,5 +1,3 @@
require 'spec_helper'
feature 'procedure locked' do
let(:administrateur) { create(:administrateur) }

View file

@ -1,4 +1,3 @@
require 'spec_helper'
require 'features/admin/procedure_spec_helper'
feature 'Administrateurs can edit procedures', js: true do

View file

@ -1,5 +1,3 @@
require 'spec_helper'
feature 'France Connect Particulier Connexion' do
let(:code) { 'plop' }
let(:given_name) { 'titi' }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
feature 'Getting help:' do
scenario 'a Help button is visible on public pages' do
visit '/'

View file

@ -1,5 +1,3 @@
require 'spec_helper'
feature 'Inviting an expert:' do
include ActiveJob::TestHelper
include ActionView::Helpers

View file

@ -1,5 +1,3 @@
require 'spec_helper'
feature 'As an instructeur', js: true do
let(:administrateur) { create(:administrateur, :with_procedure) }
let(:procedure) { administrateur.procedures.first }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
feature 'Instructing a dossier:' do
include ActiveJob::TestHelper

View file

@ -1,5 +1,3 @@
require "spec_helper"
feature "procedure filters" do
let(:instructeur) { create(:instructeur) }
let(:procedure) { create(:procedure, :published, :with_type_de_champ, instructeurs: [instructeur]) }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
feature 'As an administrateur I can edit types de champ', js: true do
let(:administrateur) { procedure.administrateurs.first }
let(:procedure) { create(:procedure) }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
feature 'Outdated browsers support:' do
context 'when the user browser is outdated' do
before(:each) do

View file

@ -1,5 +1,3 @@
require 'spec_helper'
feature 'The routing', js: true do
let(:password) { 'a very complicated password' }
let(:procedure) { create(:procedure, :with_type_de_champ, :with_service, :for_individual) }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
feature 'Signin in:' do
let!(:user) { create(:user, password: password) }
let(:password) { 'démarches-simplifiées-pwd' }

View file

@ -1,5 +1,3 @@
require 'rails_helper'
feature 'The user' do
let(:password) { 'démarches-simplifiées-pwd' }
let!(:user) { create(:user, password: password) }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
feature 'Changing an email' do
let(:old_email) { 'old@email.com' }
let(:user) { create(:user, email: old_email) }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
feature 'Creating a new dossier:' do
let(:user) { create(:user) }
let(:siret) { '40307130100044' }

View file

@ -1,4 +1,3 @@
require 'spec_helper'
require 'features/users/dossier_shared_examples.rb'
feature 'Invitations' do

View file

@ -1,5 +1,3 @@
require 'spec_helper'
feature 'linked dropdown lists' do
let(:password) { 'démarches-simplifiées-pwd' }
let!(:user) { create(:user, password: password) }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe 'user access to the list of their dossiers' do
let(:user) { create(:user) }
let!(:dossier_brouillon) { create(:dossier, user: user) }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
feature 'Managing password:' do
context 'for simple users' do
let(:user) { create(:user) }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
feature 'Sign out' do
context 'when a user is logged in' do
let(:user) { create(:administrateur).user }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
feature 'Signing up:' do
let(:user_email) { generate :user_email }
let(:user_password) { 'démarches-simplifiées-pwd' }

View file

@ -1,5 +1,3 @@
require 'rails_helper'
RSpec.describe CommentaireHelper, type: :helper do
let(:commentaire) { create(:commentaire, email: "michel@pref.fr") }

View file

@ -1,5 +1,3 @@
require 'rails_helper'
RSpec.describe ConservationDeDonneesHelper, type: :helper do
let(:procedure) { build(:procedure, duree_conservation_dossiers_dans_ds: dans_ds, duree_conservation_dossiers_hors_ds: hors_ds) }

View file

@ -1,5 +1,3 @@
require 'rails_helper'
RSpec.describe DossierHelper, type: :helper do
describe ".highlight_if_unseen_class" do
let(:seen_at) { Time.zone.now }

View file

@ -1,5 +1,3 @@
require 'rails_helper'
RSpec.describe AdministrateurActivateBeforeExpirationJob, type: :job do
describe 'perform' do
let(:administrateur) { create(:administrateur) }

View file

@ -1,4 +1,3 @@
require 'rails_helper'
include ActiveJob::TestHelper
RSpec.describe ApplicationJob, type: :job do

View file

@ -1,5 +1,3 @@
require 'rails_helper'
RSpec.describe AutoArchiveProcedureJob, type: :job do
let!(:procedure) { create(:procedure, :published, :with_instructeur, auto_archive_on: nil) }
let!(:procedure_hier) { create(:procedure, :published, :with_instructeur, auto_archive_on: 1.day.ago.to_date) }

View file

@ -1,5 +1,3 @@
require 'rails_helper'
RSpec.describe DeclarativeProceduresJob, type: :job do
describe "perform" do
let(:date) { Time.utc(2017, 9, 1, 10, 5, 0) }

View file

@ -1,5 +1,3 @@
require 'rails_helper'
RSpec.describe FindDubiousProceduresJob, type: :job do
describe 'perform' do
let(:mailer_double) { double('mailer', deliver_later: true) }

View file

@ -1,5 +1,3 @@
require 'rails_helper'
RSpec.describe WeeklyOverviewJob, type: :job do
describe 'perform' do
let!(:instructeur) { create(:instructeur) }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe ApiCarto::API do
describe '.search_qp' do
subject { described_class.search_qp(geojson) }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe ApiCarto::CadastreAdapter do
subject { described_class.new(coordinates).results }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe ApiCarto::QuartiersPrioritairesAdapter do
subject { described_class.new(coordinates).results }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe ApiEntreprise::API do
let(:procedure_id) { 12 }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe ApiEntreprise::EntrepriseAdapter do
let(:siren) { '418166096' }
let(:procedure_id) { 22 }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe ApiEntreprise::EtablissementAdapter do
let(:procedure_id) { 33 }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe ApiEntreprise::ExercicesAdapter do
let(:siret) { '41816609600051' }
let(:procedure_id) { 11 }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe ApiEntreprise::RNAAdapter do
let(:siret) { '50480511000013' }
let(:procedure_id) { 22 }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe ASN1::Timestamp do
let(:asn1timestamp) { File.read('spec/fixtures/files/bill_signature/signature.der') }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe BizDev, lib: true do
let(:first_biz_dev_id) { BizDev::PIPEDRIVE_ID }
let(:non_biz_dev_id) { first_biz_dev_id - 1 }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Helpscout::FormAdapter do
describe '#send_form' do
let(:api) { spy(double(:api)) }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Helpscout::UserConversationsAdapter do
let(:from) { Date.new(2017, 11) }
let(:to) { Date.new(2017, 12) }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Pipedrive::DealAdapter do
let(:url) { PIPEDRIVE_API_URL }
let(:status) { 200 }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe 'graphql' do
let(:current_defn) { Api::V2::Schema.to_definition }
let(:printout_defn) { File.read(Rails.root.join('app', 'graphql', 'schema.graphql')) }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe ProgressReport, lib: true do
context 'when the count pass above 100%' do
let(:total) { 2 }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Typhoeus::Cache::SuccessfulRequestsRailsCache, lib: true do
let(:cache) { described_class.new }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Universign::API do
describe '.request_timestamp', vcr: { cassette_name: 'universign' } do
subject { described_class.timestamp(digest) }

View file

@ -1,5 +1,3 @@
require "rails_helper"
RSpec.describe AvisMailer, type: :mailer do
describe '.avis_invitation' do
let(:avis) { create(:avis) }

View file

@ -1,5 +1,3 @@
require "rails_helper"
RSpec.describe DossierMailer, type: :mailer do
let(:to_email) { 'instructeur@exemple.gouv.fr' }

View file

@ -1,5 +1,3 @@
require "spec_helper"
RSpec.describe NotificationMailer, type: :mailer do
let(:user) { create(:user) }
let(:procedure) { create(:simple_procedure) }

View file

@ -1,5 +1,3 @@
require "rails_helper"
RSpec.describe UserMailer, type: :mailer do
let(:user) { build(:user) }

View file

@ -1,5 +1,3 @@
require "rails_helper"
describe Rack::Attack, type: :request do
let(:limit) { 5 }
let(:period) { 20 }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Administrateur, type: :model do
let(:administration) { create(:administration) }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Administration, type: :model do
describe '#invite_admin' do
let(:administration) { create :administration }

View file

@ -1,5 +1,3 @@
require 'rails_helper'
RSpec.describe Avis, type: :model do
let(:claimant) { create(:instructeur) }

View file

@ -1,5 +1,3 @@
require 'rails_helper'
RSpec.describe BillSignature, type: :model do
describe 'validations' do
subject(:bill_signature) { BillSignature.new }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Champ do
describe '#private?' do
let(:type_de_champ) { build(:type_de_champ, :private) }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Champ do
require 'models/champ_shared_example.rb'

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Champs::CarteChamp do
let(:champ) { Champs::CarteChamp.new(value: value) }
let(:value) { '' }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Champs::CheckboxChamp do
let(:checkbox) { Champs::CheckboxChamp.new(value: value) }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Champs::DecimalNumberChamp do
subject { build(:champ_decimal_number, value: value).tap(&:valid?) }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Champs::HeaderSectionChamp do
describe '#section_index' do
let(:types_de_champ) do

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Champs::IntegerNumberChamp do
subject { build(:champ_integer_number, value: value).tap(&:valid?) }

View file

@ -1,5 +1,3 @@
require 'spec_helper'
describe Champs::LinkedDropDownListChamp do
describe '#unpack_value' do
let(:champ) { described_class.new(value: '["tata", "tutu"]') }

Some files were not shown because too many files have changed in this diff Show more