Rails - How to test that ActionMailer sent a specific attachment?

Here's an example that I copied from my rspec test of a specific attachment, hope that it helps (mail can be creating by calling your mailer method or peeking at the deliveries array after calling .deliver):

  mail.attachments.should have(1).attachment
  attachment = mail.attachments[0]
  attachment.should be_a_kind_of(Mail::Part)
  attachment.content_type.should be_start_with('application/ics;')
  attachment.filename.should == 'event.ics'

I had something similar where I wanted to check an attached csv's content. I needed something like this because it looks like \r got inserted for newlines:

expect(mail.attachments.first.body.encoded.gsub(/\r/, '')).to(
  eq(
    <<~CSV
      "Foo","Bar"
      "1","2"
    CSV
  )
)