Hello here,
I got a trouble with mail in a rails 6.0 application (actionmailer 6.0.3.4, ruby 2.7.2, mail 2.7.1).
My rspec test is as follow:
```
some_action_supposed_to_send_an_email
expect(ActionMailer::Base.deliveries).to_not be_empty
mail = ActionMailer::Base.deliveries.pop
expect(mail.subject).to eq 'something'
# binding.pry
expect(mail.text_part.body.to_s).to eq 'some content'
```
When I run this test, I catch a nil value on `mail.text_part` and the test fails…
Debugging with the `binding.pry` uncommented, I observed the mail structure is correct but `body.parts` is not filled correctly:
```
> mail
=> #<Mail::Message:18760, Multipart: false, Headers: <Date: Fri, 01 Jan 2021 21:51:06 +0100>, <From:
monit...@example.org>, <Reply-To:
nor...@example.org>, <To:
moni...@example.org>, <Message-ID: <5fef8b3a43bd8...@endor.mail>>, <Subject: Service is DOWN: [ping] test>, <Mime-Version: 1.0>, <Content-Type: text/plain>, <Content-Transfer-Encoding: 7bit>>
> mail.text_part
=> nil
> mail.body.parts
=> []
```
If I force something I don't identify very well at the moment with a `mail.part` call, `body.parts` is now correctly filled and `mail.text_part` returns correct content:
```
> mail.part
=> [#<Mail::Part:18760, Multipart: false, Headers: <Content-Type: text/plain;>>,
#<Mail::Part:18780, Multipart: false, Headers: >]
> mail.body.parts
=> [#<Mail::Part:18760, Multipart: false, Headers: <Content-Type: text/plain;>>,
#<Mail::Part:18780, Multipart: false, Headers: >]
> mail.text_part
=> #<Mail::Part:18760, Multipart: false, Headers: <Content-Type: text/plain;>>
=>
```
And so adding a dangling `mail.part` just before expectations allows the test to pass.
And it's not satisfying at all :D
What's the trouble in my case and why mail seems not completely parsed during rspec?
Regards,