> For the complete documentation index, see [llms.txt](https://ploegert.gitbook.io/til/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ploegert.gitbook.io/til/programmy/rails/test-if-deliver-later-is-called-for-a-mailer.md).

# Test If deliver\_later Is Called For A Mailer

There are many ways to test in your controller whether emails are going out. A concise and quick way to check is just to see if a `deliver_later` happened.

Depending on how your test environment is configured, this could look one of two ways.

If you have your `queue_adapter` set to [`:inline`](https://api.rubyonrails.org/classes/ActiveJob/QueueAdapters/InlineAdapter.html), then a `deliver_later` will happen synchronously. So, the email will immediately end up in the `deliveries` box.

```ruby
expect {
  post :password_reset, params: valid_params
}.to change { ActionMailer::Base.deliveries.count }.by(1)
```

The behavior is a bit different if your `queue_adapter` is set to something like [`:test`](https://api.rubyonrails.org/classes/ActiveJob/QueueAdapters/TestAdapter.html). In this case, the email is going to be queued in the app's job queue. Since it is not immediately being sent, the expectation will have to be about the job queue instead.

```ruby
expect {
  post :password_reset, params: valid_params
}.to have_enqueued_job(ActionMailer::DeliveryJob)
```

We can even dig into more specifics like this:

```ruby
expect {
  post :password_reset, params: valid_params
}.to have_enqueued_job(ActionMailer::DeliveryJob)
  .with('UserMailer', 'password_reset', 'deliver_later', Integer)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ploegert.gitbook.io/til/programmy/rails/test-if-deliver-later-is-called-for-a-mailer.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
