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 +4 -4
- data/lib/email_test_helpers/version.rb +1 -1
- data/lib/email_test_helpers.rb +14 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c7c7d969b8a136bdd87b2be431e0dca50a9cbf3
|
4
|
+
data.tar.gz: e401fbf14801efc503638fd9224998f206930f94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c77a5054038536275a53db98a7452fd0387f1807ee29dc273b9c82936f910cb035e02336c55d19b1e89bcf4a1b5e498160e3847c2e10ef7bd43359ebf34e8a37
|
7
|
+
data.tar.gz: 773284f7099f0ff04dd785a9b5235dd598896c49d7a1e6e3298d471019086a78904c694ea32ac875d0d954be8a5cf9643db3a07cf552be75cd10767b7cc477d6
|
data/lib/email_test_helpers.rb
CHANGED
@@ -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(
|
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(
|
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
|
57
|
-
|
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.
|
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-
|
11
|
+
date: 2015-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionmailer
|