Class: MailCapture::Inbox
- Inherits:
-
Object
- Object
- MailCapture::Inbox
- Defined in:
- lib/mailcapture/inbox.rb
Overview
A scoped handle for a single capture inbox (tag). Create one with Client#inbox.
Keeps test code clean by binding the tag once:
inbox = mc.inbox('signup')
inbox.clear
MyApp.register(inbox.address)
email = inbox.wait_for(timeout: 15)
expect(email.otp).to match(/\A\d{6}\z/)
Instance Attribute Summary collapse
-
#tag ⇒ String
readonly
The tag this inbox is scoped to.
Instance Method Summary collapse
-
#address ⇒ Object
The full capture email address for this inbox, e.g.
-
#clear ⇒ Object
Delete all captures.
-
#initialize(client, tag) ⇒ Inbox
constructor
A new instance of Inbox.
-
#list(limit: nil, after: nil) ⇒ Object
List recent captures.
- #to_s ⇒ Object (also: #inspect)
-
#wait_for(timeout: 30, poll_timeout: 10, after: nil) ⇒ Object
Wait for an email to arrive.
Constructor Details
#initialize(client, tag) ⇒ Inbox
Returns a new instance of Inbox.
16 17 18 19 |
# File 'lib/mailcapture/inbox.rb', line 16 def initialize(client, tag) @client = client @tag = tag end |
Instance Attribute Details
#tag ⇒ String (readonly)
Returns the tag this inbox is scoped to.
14 15 16 |
# File 'lib/mailcapture/inbox.rb', line 14 def tag @tag end |
Instance Method Details
#address ⇒ Object
The full capture email address for this inbox, e.g. “alice-signup@mailcapture.app”.
Requires ping to have been called first, or :username set in the constructor.
27 28 29 |
# File 'lib/mailcapture/inbox.rb', line 27 def address @client.address(tag) end |
#clear ⇒ Object
Delete all captures. Call before each test for a clean starting state.
before(:each) { inbox.clear }
44 45 46 |
# File 'lib/mailcapture/inbox.rb', line 44 def clear @client.delete(tag) end |
#list(limit: nil, after: nil) ⇒ Object
List recent captures. See Client#list.
37 38 39 |
# File 'lib/mailcapture/inbox.rb', line 37 def list(limit: nil, after: nil) @client.list(tag: tag, limit: limit, after: after) end |
#to_s ⇒ Object Also known as: inspect
48 49 50 |
# File 'lib/mailcapture/inbox.rb', line 48 def to_s "#<MailCapture::Inbox tag=#{tag.inspect}>" end |
#wait_for(timeout: 30, poll_timeout: 10, after: nil) ⇒ Object
Wait for an email to arrive. See Client#wait_for.
32 33 34 |
# File 'lib/mailcapture/inbox.rb', line 32 def wait_for(timeout: 30, poll_timeout: 10, after: nil) @client.wait_for(tag, timeout: timeout, poll_timeout: poll_timeout, after: after) end |