cucumber-mailcatcher 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 77a8bcce717891fae6839e7f0c4812c16a1f2829
4
+ data.tar.gz: c368c81e98bcc771b5874964c5dd0f4b312e21c9
5
+ SHA512:
6
+ metadata.gz: b7a4ee7939396498e9759d2f21dd4de1cfeadf16ee94170cd344629284cb133896a3a0f9fe1c8bcd0235d5a8a507e3b54e6afc9f32949e136a1562e92c351703
7
+ data.tar.gz: 77de4406d2e13080360ee0caa451274528e2fa6b7457e3e08064e91ab6b0f24c553177ddc23074176e3d9a9d8249fc33cc06c29ba7c4b6a146dd0e0a7dc723d7
@@ -0,0 +1,18 @@
1
+ require 'jsonpath'
2
+ require 'nokogiri'
3
+
4
+ require 'cucumber'
5
+ require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
6
+
7
+ require 'cucumber/mailcatcher/http_client.rb'
8
+
9
+ module Cucumber
10
+ module Mailcatcher
11
+ def self.mailcatcher_steps
12
+ t = ["#{File.dirname(File.expand_path($0))}/../lib/#{FOLDER}",
13
+ "#{Gem.dir}/gems/#{NAME}-#{VERSION}/lib/#{FOLDER}"]
14
+ t.each {|i| return "#{i}/mailcatcher_steps.rb" if File.readable?(i) }
15
+ raise "both paths are invalid: #{t}"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,81 @@
1
+ require "net/http"
2
+ require "net/https"
3
+ require "uri"
4
+ require 'json'
5
+
6
+ module Cucumber
7
+ module Mailcatcher
8
+
9
+ class HttpClient
10
+ attr_accessor :server_url
11
+
12
+ def get_messages
13
+ do_get_json '/messages'
14
+ end
15
+
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
+ }
22
+ end
23
+
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
57
+
58
+ def delete_messages
59
+ do_delete '/messages'
60
+ true
61
+ end
62
+
63
+ def do_get relative_url
64
+ uri = URI("#{@server_url}#{relative_url}")
65
+ Net::HTTP.get_response(uri)
66
+ end
67
+
68
+ def do_get_json relative_url
69
+ JSON.load((do_get relative_url).body )
70
+ end
71
+
72
+ def do_delete relative_url
73
+ uri = URI("#{@server_url}#{relative_url}")
74
+
75
+ request = Net::HTTP.new(uri.host,uri.port)
76
+ request.delete(uri.path).code
77
+ end
78
+ end
79
+
80
+ end
81
+ end
@@ -0,0 +1,24 @@
1
+ Given(/^I should receive "([0-9])" email from "([^"]*)"/) do |count, address|
2
+ messages = subject.get_messages_from_email address
3
+ expect(messages.length).to be count
4
+ end
5
+
6
+ Given(/^I should receive "([0-9])" email sent to "([^"]*)"/) do |count, address|
7
+ messages = subject.get_messages_to_email address
8
+ expect(messages.length).to be count
9
+ end
10
+
11
+ Given(/^I should receive "([0-9])" email with subject "([^"]*)"/) do |count, subject|
12
+ messages = subject.get_messages_with_subject subject
13
+ expect(messages.length).to be count
14
+ end
15
+
16
+ Given(/^I should receive "([0-9])" email with a html body containing "([^"]*)"/) do |count, body|
17
+ messages = subject.get_messages_with_html_body body
18
+ expect(messages.length).to be count
19
+ end
20
+
21
+ Given(/^I should receive "([0-9])" email with a plain body containing "([^"]*)"/) do |count, body|
22
+ messages = subject.get_messages_with_plain_body body
23
+ expect(messages.length).to be count
24
+ end
@@ -0,0 +1,7 @@
1
+ module Cucumber
2
+ module Mailcatcher
3
+ NAME = "cucumber-mailcatcher"
4
+ FOLDER = "cucumber/mailcatcher"
5
+ VERSION = "0.1"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cucumber-mailcatcher
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Nic Jackson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cucumber
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.3.10
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.3.10
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec-expectations
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.3'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 3.3.1
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '3.3'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 3.3.1
53
+ description: Some simple cucumber steps to allow behavioural testing with the Mailcatcher
54
+ mock SMTP server
55
+ email: jackson.nic@gmail.com
56
+ executables: []
57
+ extensions: []
58
+ extra_rdoc_files: []
59
+ files:
60
+ - lib/cucumber/mailcatcher.rb
61
+ - lib/cucumber/mailcatcher/http_client.rb
62
+ - lib/cucumber/mailcatcher/mailcatcher_steps.rb
63
+ - lib/cucumber/mailcatcher/version.rb
64
+ homepage: https://github.com/nicholasjackson/cucumber-mailcatcher
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 2.2.2
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Cucumber steps for Mailcatcher mock SMTP server
88
+ test_files: []