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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d1fa7791588641edf58ea0e8406865ec55d26238
4
- data.tar.gz: a4317311f8ceff0f21aad6c0cb7d49064e1637d0
3
+ metadata.gz: b59409830fa2ba344feb79c06a6e158644a21227
4
+ data.tar.gz: dfc0af6762b819b532df0392548fb848e3667615
5
5
  SHA512:
6
- metadata.gz: 054812999f9f3378c8263dd2b8e4a2ddbac563b81dbce2975be58eaa1ee1ff0107ae75a22b004cce2cc215ab66052ec04973acdc1cc1bd4725ff7cc1ee90f4fe
7
- data.tar.gz: fee6c77cbe105ac6a0fb0c53236815d1e6039a11cf300508b5c8543a3a54cdeab6da685fc864b04574522583ff6ab5c5d1407963784f93745d67130e542273ec
6
+ metadata.gz: 6ed9b02b721e07716174b4424eb5a55ea555c48db14d31dac24a740eeb88d8abfa35c5418b10a6d3fa869475f0bda3aa32d62d381d65fe56cbf870a46cbf0eef
7
+ data.tar.gz: b62d380ddde8eb3f0b9735b9e38d394eb3d86d3541fd2f2c3dc358f9440b9535af269ca4cd9bd8e9ffcbe2c5abff50dc5be5afcb0cbb58e2c2599e94a960f628
@@ -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
- messages = subject.get_messages_from_email address
12
- expect(messages.length).to be count
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
- messages = subject.get_messages_to_email address
17
- expect(messages.length).to be count
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
- messages = subject.get_messages_with_subject subject
22
- expect(messages.length).to be count
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
- messages = subject.get_messages_with_html_body body
27
- expect(messages.length).to be count
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
- messages = subject.get_messages_with_plain_body body
32
- expect(messages.length).to be count
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
- attr_accessor :server_url
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 get_messages_from_email email
17
- messages = do_get_json '/messages'
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 get_messages_to_email email
25
- messages = do_get_json '/messages'
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
- def delete_messages
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("#{@server_url}#{relative_url}")
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("#{@server_url}#{relative_url}")
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
@@ -2,6 +2,6 @@ module Cucumber
2
2
  module Mailcatcher
3
3
  NAME = "cucumber-mailcatcher"
4
4
  FOLDER = "cucumber/mailcatcher"
5
- VERSION = "0.5"
5
+ VERSION = "0.6"
6
6
  end
7
7
  end
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.5'
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-01 00:00:00.000000000 Z
11
+ date: 2015-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cucumber