diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index a113cfd84..4ff839507 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -170,14 +170,14 @@ describe User, type: :model do let(:administrateur) { create(:administrateur) } let(:user) { administrateur.user } + let(:mailer_double) { double('mailer', deliver_later: true) } + + before { allow(AdministrationMailer).to receive(:invite_admin).and_return(mailer_double) } + subject { user.invite_administrateur!(administration.id) } context 'when the user is inactif' do - before do - mailer_double = double('mailer', deliver_later: true) - allow(AdministrationMailer).to receive(:invite_admin).and_return(mailer_double) - subject - end + before { subject } it { expect(AdministrationMailer).to have_received(:invite_admin).with(user, kind_of(String), administration.id) } end @@ -185,8 +185,6 @@ describe User, type: :model do context 'when the user is actif' do before do user.update(last_sign_in_at: Time.zone.now) - mailer_double = double('mailer', deliver_later: true) - allow(AdministrationMailer).to receive(:invite_admin).and_return(mailer_double) subject end