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

前端 未结 2 677
自闭症患者
自闭症患者 2021-02-05 02:17

In my ActionMailer::TestCase test, I\'m expecting:

@expected.to      = BuyadsproMailer.group_to(campaign.agency.users)
@expected.subject = \"You submitted #{off         


        
相关标签:
2条回答
  • 2021-02-05 02:55

    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
      )
    ) 
    
    0 讨论(0)
  • 2021-02-05 03:00

    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'
    
    0 讨论(0)
提交回复
热议问题