cucumber-mailcatcher 0.5 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cucumber/mailcatcher.rb +17 -10
- data/lib/cucumber/mailcatcher/http_client.rb +11 -49
- data/lib/cucumber/mailcatcher/version.rb +1 -1
- 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: b59409830fa2ba344feb79c06a6e158644a21227
|
4
|
+
data.tar.gz: dfc0af6762b819b532df0392548fb848e3667615
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ed9b02b721e07716174b4424eb5a55ea555c48db14d31dac24a740eeb88d8abfa35c5418b10a6d3fa869475f0bda3aa32d62d381d65fe56cbf870a46cbf0eef
|
7
|
+
data.tar.gz: b62d380ddde8eb3f0b9735b9e38d394eb3d86d3541fd2f2c3dc358f9440b9535af269ca4cd9bd8e9ffcbe2c5abff50dc5be5afcb0cbb58e2c2599e94a960f628
|
data/lib/cucumber/mailcatcher.rb
CHANGED
@@ -8,26 +8,33 @@ require 'cucumber/mailcatcher/http_client.rb'
|
|
8
8
|
require 'cucumber/mailcatcher/version.rb'
|
9
9
|
|
10
10
|
Then /^I should receive (\d+) email from "(.*?)"$/ do |count, address|
|
11
|
-
|
12
|
-
|
11
|
+
http = Cucumber::Mailcatcher::HttpClient.new
|
12
|
+
messages = http.get_messages_from_email address
|
13
|
+
expect(messages.length).to be count.to_i
|
13
14
|
end
|
14
15
|
|
15
16
|
Then /^I should receive (\d+) email sent to "(.*?)"$/ do |count, address|
|
16
|
-
|
17
|
-
|
17
|
+
http = Cucumber::Mailcatcher::HttpClient.new
|
18
|
+
messages = http.get_messages_to_email address
|
19
|
+
expect(messages.length).to be count.to_i
|
18
20
|
end
|
19
21
|
|
20
22
|
Then /^I should receive (\d+) email with subject "(.*?)"$/ do |count, subject|
|
21
|
-
|
22
|
-
|
23
|
+
http = Cucumber::Mailcatcher::HttpClient.new
|
24
|
+
messages = http.get_messages_with_subject subject
|
25
|
+
expect(messages.length).to be count.to_i
|
23
26
|
end
|
24
27
|
|
25
28
|
Then /^I should receive (\d+) email with a html body containing "(.*?)"$/ do |count, body|
|
26
|
-
|
27
|
-
|
29
|
+
http = Cucumber::Mailcatcher::HttpClient.new
|
30
|
+
p $EMAIL_SERVER_PATH
|
31
|
+
http.server_url = $EMAIL_SERVER_PATH
|
32
|
+
messages = http.get_messages_with_html_body body
|
33
|
+
expect(messages.length).to be count.to_i
|
28
34
|
end
|
29
35
|
|
30
36
|
Then /^I should receive (\d+) email with a plain body containing "(.*?)"$/ do |count, body|
|
31
|
-
|
32
|
-
|
37
|
+
http = Cucumber::Mailcatcher::HttpClient.new
|
38
|
+
messages = http.get_messages_with_plain_body body
|
39
|
+
expect(messages.length).to be count.to_i
|
33
40
|
end
|
@@ -7,70 +7,32 @@ module Cucumber
|
|
7
7
|
module Mailcatcher
|
8
8
|
|
9
9
|
class HttpClient
|
10
|
-
|
11
|
-
|
12
|
-
def get_messages
|
13
|
-
do_get_json '/messages'
|
10
|
+
def self.server_url
|
11
|
+
@@server_url
|
14
12
|
end
|
15
13
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
19
|
-
messages.select { |item|
|
20
|
-
item if item["sender"].include?(email)
|
21
|
-
}
|
14
|
+
def self.server_url=server_url
|
15
|
+
@@server_url = server_url
|
22
16
|
end
|
23
17
|
|
24
|
-
def
|
25
|
-
|
26
|
-
|
27
|
-
messages.select { |item|
|
28
|
-
item if item["recipients"].include?(email) || item["recipients"].include?('<' + email + '>')
|
29
|
-
}
|
30
|
-
end
|
31
|
-
|
32
|
-
def get_messages_with_subject subject
|
33
|
-
messages = do_get_json '/messages'
|
34
|
-
|
35
|
-
messages.select { |item|
|
36
|
-
item if item["subject"].include?(subject)
|
37
|
-
}
|
38
|
-
end
|
39
|
-
|
40
|
-
def get_messages_with_html_body body
|
41
|
-
messages = do_get_json '/messages'
|
42
|
-
|
43
|
-
messages.select { |item|
|
44
|
-
response = do_get "/messages/#{item['id']}.json.html"
|
45
|
-
item if response.code != '404' && response.body.include?(body)
|
46
|
-
}
|
47
|
-
end
|
48
|
-
|
49
|
-
def get_messages_with_plain_body body
|
50
|
-
messages = do_get_json '/messages'
|
51
|
-
|
52
|
-
messages.select { |item|
|
53
|
-
response = do_get "/messages/#{item['id']}.json.plain"
|
54
|
-
item if response.code != '404' && response.body.include?(body)
|
55
|
-
}
|
56
|
-
end
|
18
|
+
def initialize
|
19
|
+
error = "Please set the Mailcatcher server url e.g. Cucumber::Mailcatcher::Api.server_url = 'http://localhost:1080'"
|
20
|
+
valid = @@server_url =~ /\A#{URI.regexp(%w(http https))}\z/
|
57
21
|
|
58
|
-
|
59
|
-
do_delete '/messages'
|
60
|
-
true
|
22
|
+
raise error unless valid
|
61
23
|
end
|
62
24
|
|
63
25
|
def do_get relative_url
|
64
|
-
uri = URI("#{
|
26
|
+
uri = URI("#{@@server_url}#{relative_url}")
|
65
27
|
Net::HTTP.get_response(uri)
|
66
28
|
end
|
67
29
|
|
68
30
|
def do_get_json relative_url
|
69
|
-
JSON.load((do_get relative_url).body
|
31
|
+
JSON.load((do_get relative_url).body)
|
70
32
|
end
|
71
33
|
|
72
34
|
def do_delete relative_url
|
73
|
-
uri = URI("#{
|
35
|
+
uri = URI("#{@@server_url}#{relative_url}")
|
74
36
|
|
75
37
|
request = Net::HTTP.new(uri.host,uri.port)
|
76
38
|
request.delete(uri.path).code
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cucumber-mailcatcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.6'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nic Jackson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cucumber
|