Module: Pickle::Email

Defined in:
lib/pickle/email.rb,
lib/pickle/email/parser.rb

Defined Under Namespace

Modules: Parser

Instance Method Summary (collapse)

Instance Method Details



26
27
28
29
# File 'lib/pickle/email.rb', line 26

def click_first_link_in_email(email)
  link = links_in_email(email).first
  visit link
end

- (Object) email(ref, fields = nil)



8
9
10
11
12
13
# File 'lib/pickle/email.rb', line 8

def email(ref, fields = nil)
  (match = ref.match(/^#{capture_index_in_email}$/)) or raise ArgumentError, "argument should match #{match_email}"
  @emails or raise RuntimeError, "Call #emails before calling #email"
  index = parse_index(match[1])
  email_has_fields?(@emails[index], fields) ? @emails[index] : nil
end

- (Boolean) email_has_fields?(email, fields)



15
16
17
18
19
20
# File 'lib/pickle/email.rb', line 15

def email_has_fields?(email, fields)
  parse_fields(fields).each do |key, val|
    return false unless (Array(email.send(key)) & Array(val)).any?
  end
  true
end

- (Object) emails(fields = nil)

return the deliveries array, optionally selected by the passed fields



4
5
6
# File 'lib/pickle/email.rb', line 4

def emails(fields = nil)
  @emails = ActionMailer::Base.deliveries.select {|m| email_has_fields?(m, fields)}
end

- (Object) visit_in_email(email, link_text)



22
23
24
# File 'lib/pickle/email.rb', line 22

def visit_in_email(email, link_text)
  visit(parse_email_for_link(email, link_text))
end