File tree 4 files changed +26
-0
lines changed
4 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -16,5 +16,6 @@ Compatibility:
16
16
17
17
Features:
18
18
* Message#inspect_structure and PartsList#inspect_structure pretty-print the hierarchy of message parts. (TylerRick)
19
+ * `an_attachment_with_mime_type` matcher added to match attachments by mime type
19
20
20
21
Please check [2-7-stable](https://github.com/mikel/mail/blob/2-7-stable/CHANGELOG.rdoc) for previous changes.
Original file line number Diff line number Diff line change @@ -645,6 +645,12 @@ describe "sending an email" do
645
645
# ... or any attachment
646
646
it { is_expected.to have_sent_email.with_attachments(any_attachment) }
647
647
648
+ # ... or attachment with filename
649
+ it { is_expected.to have_sent_email.with_attachments(an_attachment_with_filename(' file.txt' )) }
650
+
651
+ # ... or attachment with mime_type
652
+ it { is_expected.to have_sent_email.with_attachments(an_attachment_with_mime_type(' application/pdf' )) }
653
+
648
654
# ... by array of attachments
649
655
it { is_expected.to have_sent_email.with_attachments([my_attachment1, my_attachment2]) } # note that order is important
650
656
Original file line number Diff line number Diff line change @@ -9,6 +9,10 @@ def an_attachment_with_filename(filename)
9
9
AttachmentFilenameMatcher . new ( filename )
10
10
end
11
11
12
+ def an_attachment_with_mime_type ( filename )
13
+ AttachmentMimeTypeMatcher . new ( filename )
14
+ end
15
+
12
16
class AnyAttachmentMatcher
13
17
def ===( other )
14
18
other . attachment?
@@ -25,5 +29,16 @@ def ===(other)
25
29
other . attachment? && other . filename == filename
26
30
end
27
31
end
32
+
33
+ class AttachmentMimeTypeMatcher
34
+ attr_reader :mime_type
35
+ def initialize ( mime_type )
36
+ @mime_type = mime_type
37
+ end
38
+
39
+ def ===( other )
40
+ other . attachment? && other . mime_type == mime_type
41
+ end
42
+ end
28
43
end
29
44
end
Original file line number Diff line number Diff line change 176
176
it { is_expected . to have_sent_email . with_attachments ( an_attachment_with_filename ( first_attachment . filename ) ) }
177
177
end
178
178
179
+ context 'matching by mimetype' do
180
+ it { is_expected . to have_sent_email . with_attachments ( an_attachment_with_mime_type ( first_attachment . mime_type ) ) }
181
+ end
182
+
179
183
context 'single attachment passed' do
180
184
it { is_expected . to have_sent_email . with_attachments ( first_attachment ) }
181
185
end
You can’t perform that action at this time.
0 commit comments