Module: Capybara::Email::DSL

Defined in:
lib/capybara/email/dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_emailMail::Message?

Returns the currently set email. If no email set will return nil.

Returns:

  • (Mail::Message, nil)

7
8
9
# File 'lib/capybara/email/dsl.rb', line 7

def current_email
  @current_email
end

#current_emailsArray<Mail::Message>

Returns a collection of all current emails retrieved

Returns:

  • (Array<Mail::Message>)

42
43
44
# File 'lib/capybara/email/dsl.rb', line 42

def current_emails
  @current_emails
end

Instance Method Details

#all_emailsArray

Access all emails

Returns:

  • (Array)

13
14
15
# File 'lib/capybara/email/dsl.rb', line 13

def all_emails
  Mail::TestMailer.deliveries
end

#clear_emailsObject Also known as: clear_email

Clear the email queue


47
48
49
50
51
# File 'lib/capybara/email/dsl.rb', line 47

def clear_emails
  all_emails.clear
  self.current_emails = nil
  self.current_email  = nil
end

#emails_sent_to(recipient) ⇒ Array<Mail::Message>

Access all emails for a recipient.

Parameters:

  • (String)

Returns:

  • (Array<Mail::Message>)

22
23
24
25
26
27
# File 'lib/capybara/email/dsl.rb', line 22

def emails_sent_to(recipient)
  self.current_emails = all_emails.select { |email| [email.to, email.cc, email.bcc].flatten.compact.include?(recipient) }.map do |email|
    driver = Capybara::Email::Driver.new(email)
    Capybara::Node::Email.new(Capybara.current_session, driver)
  end
end

#first_email_sent_to(recipient) ⇒ Mail::Message Also known as: open_email

Access the first email for a recipient and set it to.

Parameters:

  • (String)

Returns:

  • (Mail::Message)

34
35
36
# File 'lib/capybara/email/dsl.rb', line 34

def first_email_sent_to(recipient)
  self.current_email = emails_sent_to(recipient).last
end