email_test_helpers 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc81fae29b6e49a70e40fdad04f389f42cc4d96f
4
- data.tar.gz: 672c23936a333028242072bd5484c4fea092a8ce
3
+ metadata.gz: 7c7c7d969b8a136bdd87b2be431e0dca50a9cbf3
4
+ data.tar.gz: e401fbf14801efc503638fd9224998f206930f94
5
5
  SHA512:
6
- metadata.gz: 9d1618b30fc97c90702ab28eb9ba490924019315ca5f28ddc5812144e956b892687bf42691f7036504ff78f9f0066e48dbbe0de3b3dd07a5b89caff2af5bf55f
7
- data.tar.gz: d755826873413caed2fc1bb7d9c3cb64f17245e1c44940d9509ba4a4b3b09b21bb5c0669c88c26bbd9cf7b85e0fdb70fb135d85e37a513a4c73e9faf44f9babf
6
+ metadata.gz: c77a5054038536275a53db98a7452fd0387f1807ee29dc273b9c82936f910cb035e02336c55d19b1e89bcf4a1b5e498160e3847c2e10ef7bd43359ebf34e8a37
7
+ data.tar.gz: 773284f7099f0ff04dd785a9b5235dd598896c49d7a1e6e3298d471019086a78904c694ea32ac875d0d954be8a5cf9643db3a07cf552be75cd10767b7cc477d6
@@ -1,3 +1,3 @@
1
1
  module EmailTestHelpers
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -14,19 +14,21 @@ module EmailTestHelpers
14
14
  end
15
15
 
16
16
  def find_email(options = {})
17
+ validate_options(options)
17
18
  @last_email = emails.reverse.detect do |mail|
18
19
  [
19
20
  options[:to].nil? || mail.to.include?(options[:to]),
20
21
  options[:cc].nil? || mail.cc.include?(options[:cc]),
21
22
  options[:bcc].nil? || mail.bcc.include?(options[:bcc]),
22
23
  options[:subject].nil? || options[:subject] === mail.subject,
24
+ options[:body].nil? || options[:body] === email_body(mail),
23
25
  ].all?
24
26
  end or raise(NotFound, "Couldn't find email with options: #{options.inspect}")
25
27
  end
26
28
 
27
29
  def find_email_link(key = nil)
28
30
  if key
29
- link = Capybara.string(last_email_body).all('a').detect do |element|
31
+ link = Capybara.string(email_body).all('a').detect do |element|
30
32
  case key
31
33
  when Regexp then key === element.text || key === element[:href]
32
34
  when String then element.text.downcase.include?(key.downcase) || element[:href].include?(key)
@@ -39,7 +41,7 @@ module EmailTestHelpers
39
41
  raise(NotFound, "Couldn't find link with key: #{key}")
40
42
  end
41
43
  else
42
- Capybara.string(last_email_body).first('a')['href']
44
+ Capybara.string(email_body).first('a')['href']
43
45
  end
44
46
  end
45
47
 
@@ -49,11 +51,19 @@ module EmailTestHelpers
49
51
 
50
52
  private
51
53
 
54
+ def email_body(mail = last_email)
55
+ mail.body.raw_source
56
+ end
57
+
52
58
  def last_email
53
59
  @last_email || find_email
54
60
  end
55
61
 
56
- def last_email_body
57
- last_email.body.raw_source
62
+ def validate_options(options)
63
+ valid_keys = %i[to cc bcc subject body]
64
+ invalid_keys = options.keys - valid_keys
65
+ if invalid_keys.any?
66
+ raise ArgumentError, "Invalid options detected: #{invalid_keys.join(', ')}"
67
+ end
58
68
  end
59
69
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: email_test_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zubin Henner
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-04-07 00:00:00.000000000 Z
11
+ date: 2015-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer