Module: Tape::EmailSpec::Helpers
- Defined in:
- lib/tape/email_spec/helpers.rb
Instance Method Summary collapse
- #all_emails ⇒ Object
- #click_email_link_matching(regex, email = current_email) ⇒ Object
- #click_first_link_in_email(email = current_email) ⇒ Object
- #current_email(address = nil) ⇒ Object
- #current_email_attachments(address = nil) ⇒ Object
- #find_email(address, opts = {}) ⇒ Object
- #last_email_sent ⇒ Object
- #links_in_email(email) ⇒ Object
- #open_email(address, opts = {}) ⇒ Object (also: #open_email_for)
- #open_last_email ⇒ Object
- #open_last_email_for(address) ⇒ Object
- #read_emails_for(address) ⇒ Object
- #unread_emails_for(address) ⇒ Object
- #visit_in_email(link_text) ⇒ Object
Instance Method Details
#all_emails ⇒ Object
9 10 11 |
# File 'lib/tape/email_spec/helpers.rb', line 9 def all_emails Tape.adapter.all end |
#click_email_link_matching(regex, email = current_email) ⇒ Object
21 22 23 24 25 |
# File 'lib/tape/email_spec/helpers.rb', line 21 def click_email_link_matching(regex, email = current_email) url = links_in_email(email).detect { |link| link =~ regex } raise "No link found matching #{regex.inspect} in #{email.default_part_body}" unless url visit request_uri(url) end |
#click_first_link_in_email(email = current_email) ⇒ Object
27 28 29 30 |
# File 'lib/tape/email_spec/helpers.rb', line 27 def click_first_link_in_email(email = current_email) link = links_in_email(email).first visit request_uri(link) end |
#current_email(address = nil) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/tape/email_spec/helpers.rb', line 46 def current_email(address=nil) address = convert_address(address) email = address ? email_spec_hash[:current_emails][address] : email_spec_hash[:current_email] raise RSpec::Expectations::ExpectationNotMetError, "Expected an open email but none was found. Did you forget to call open_email?" unless email email end |
#current_email_attachments(address = nil) ⇒ Object
53 54 55 |
# File 'lib/tape/email_spec/helpers.rb', line 53 def (address=nil) current_email(address). || Array.new end |
#find_email(address, opts = {}) ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/tape/email_spec/helpers.rb', line 65 def find_email(address, opts={}) address = convert_address(address) if opts[:with_subject] mailbox_for(address).find { |m| m.subject =~ Regexp.new(opts[:with_subject]) } elsif opts[:with_text] mailbox_for(address).find { |m| m.default_part_body =~ Regexp.new(opts[:with_text]) } else mailbox_for(address).first end end |
#last_email_sent ⇒ Object
13 14 15 |
# File 'lib/tape/email_spec/helpers.rb', line 13 def last_email_sent Tape.adapter.last end |
#links_in_email(email) ⇒ Object
76 77 78 |
# File 'lib/tape/email_spec/helpers.rb', line 76 def links_in_email(email) URI.extract(email.default_part_body.to_s, ['http', 'https']) end |
#open_email(address, opts = {}) ⇒ Object Also known as: open_email_for
32 33 34 |
# File 'lib/tape/email_spec/helpers.rb', line 32 def open_email(address, opts={}) set_current_email(find_email!(address, opts)) end |
#open_last_email ⇒ Object
38 39 40 |
# File 'lib/tape/email_spec/helpers.rb', line 38 def open_last_email set_current_email(last_email_sent) end |
#open_last_email_for(address) ⇒ Object
42 43 44 |
# File 'lib/tape/email_spec/helpers.rb', line 42 def open_last_email_for(address) set_current_email(mailbox_for(address).last) end |
#read_emails_for(address) ⇒ Object
61 62 63 |
# File 'lib/tape/email_spec/helpers.rb', line 61 def read_emails_for(address) email_spec_hash[:read_emails][convert_address(address)] ||= [] end |
#unread_emails_for(address) ⇒ Object
57 58 59 |
# File 'lib/tape/email_spec/helpers.rb', line 57 def unread_emails_for(address) mailbox_for(address) - read_emails_for(address) end |
#visit_in_email(link_text) ⇒ Object
17 18 19 |
# File 'lib/tape/email_spec/helpers.rb', line 17 def visit_in_email(link_text) visit(parse_email_for_link(current_email, link_text)) end |