title: Rspec test with devise mailer sending job
body: <p>I've got functionality where a user gets reminder to complete registration after 2, 10 and 26 days after first registration. How to test if email will be not sending after eg. 6 days after first registration?</p>
  
  <p><strong>jobs/remind_users_without_banker_about_unconfirmed_account.rb</strong></p>
  
  <pre><code>class RemindUsersWithoutBankerAboutUnconfirmedAccount &lt; ApplicationJob
    NUMBER_OF_DAYS_SINCE_CREATION = [2, 10, 26].freeze
  
    def perform
      RemindUnconfirmedUsersWithoutBanker.call(NUMBER_OF_DAYS_SINCE_CREATION)
    end
  end
  </code></pre>
  
  <p>this is a service where all action is made</p>
  
  <p><strong>services/remind_unconfirmed_users_without_banker.rb</strong></p>
  
  <pre><code>class RemindUnconfirmedUsersWithoutBanker &lt; ApplicationService
    def call(number_of_days)
      return Failure(:invalid_value) if invalid?(number_of_days)
  
      users_to_mail = unconfirmed_users_not_created_by_bank_employees(number_of_days)
      return Failure(:no_matching_users) if users_to_mail.empty?
  
      resend_invitation(users_to_mail)
      Success(nil)
    end
  
    private
  
    def unconfirmed_users_not_created_by_bank_employees(number_of_days)
      days_mapped_with_date = number_of_days.map { |day| day.days.ago.to_date }
  
      User.where("users.bank_employee_id IS ?
                  AND users.confirmed_at IS ?
                  AND DATE(users.created_at) IN (?)",
                 nil,
                 nil,
                 days_mapped_with_date)
    end
  
    def invalid?(number_of_days)
      number_of_days.any? { |number_of_day| !number_of_day.is_a?(Integer) || number_of_day &lt; 1 }
    end
  
    def resend_invitation(users_to_mail)
      users_to_mail.each do |user|
        Devise::Mailer.confirmation_instructions(user, user.confirmation_token).deliver_later
      end
    end
  end
  </code></pre>
  
  <p>And I have one spec where failure is returned and spec is green but it doesn't exactly simulate of sending an e-mail</p>
  
  <pre><code>RSpec.describe RemindUnconfirmedUsersWithoutBanker do
    subject(:remind_unconfirmed_users) { described_class.call(number_of_days) }
  
    let(:number_of_days) { [2, 10, 26] }
  
    before do
      ActiveJob::Base.queue_adapter = :test
      allow(InvitationMailer).to receive_message_chain(:confirmation_instructions, :deliver)
    end
  
    context "when created_at equals to 6 days" do
      it "does not invite user again" do
        create_list(:user, 2, created_at: 6.days.ago, confirmed_at: nil)
        expect(remind_unconfirmed_users).to eq(Failure(:no_matching_users))
      end
    end
  </code></pre>
  
  <p>Is there better way to check if these emails are send only on days that are mentioned (2, 10, 26)?</p>