mail_checker 0.0.1
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.
- data/.gitignore +18 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +54 -0
- data/Rakefile +1 -0
- data/lib/mail_checker.rb +17 -0
- data/lib/mail_checker/configuration.rb +14 -0
- data/lib/mail_checker/expectation.rb +26 -0
- data/lib/mail_checker/expectation_matcher.rb +46 -0
- data/lib/mail_checker/helpers.rb +7 -0
- data/lib/mail_checker/mail.rb +28 -0
- data/lib/mail_checker/matchers.rb +7 -0
- data/lib/mail_checker/version.rb +3 -0
- data/mail_checker.gemspec +20 -0
- metadata +76 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Eugenio Depalo
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# MailChecker
|
2
|
+
|
3
|
+
RSpec matchers and helpers to set expectations on mails delivered to MailCatcher
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'mail_checker'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install mail_checker
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Configure RSpec to use MailChecker:
|
22
|
+
|
23
|
+
RSpec.configure do |config|
|
24
|
+
config.include MailChecker::Helpers
|
25
|
+
config.include MailChecker::Matchers
|
26
|
+
|
27
|
+
config.before(:each) do
|
28
|
+
MailChecker.clear
|
29
|
+
end
|
30
|
+
|
31
|
+
config.before(:suite) do
|
32
|
+
MailChecker.configure do |config|
|
33
|
+
config.host = 'localhost'
|
34
|
+
config.port = 1080
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
Setup expectations in your tests:
|
40
|
+
|
41
|
+
an_email(/Example Subject/).
|
42
|
+
to('user@example.com').
|
43
|
+
from('noreply@example.com').
|
44
|
+
should have_been_delivered
|
45
|
+
|
46
|
+
Every expectation method accepts strings, regexps, arrays of strings or arrays of regexps.
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
1. Fork it
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/lib/mail_checker.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'mail_checker/version'
|
2
|
+
require 'mail_checker/mail'
|
3
|
+
require 'mail_checker/configuration'
|
4
|
+
require 'mail_checker/expectation_matcher'
|
5
|
+
require 'mail_checker/expectation'
|
6
|
+
require 'mail_checker/matchers'
|
7
|
+
require 'mail_checker/helpers'
|
8
|
+
|
9
|
+
module MailChecker
|
10
|
+
def self.configure(&block)
|
11
|
+
Configuration.new(&block).configure
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.clear
|
15
|
+
Mail.destroy_all
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module MailChecker
|
2
|
+
class Expectation
|
3
|
+
attr_reader :subject, :attributes
|
4
|
+
|
5
|
+
def initialize(subject = nil)
|
6
|
+
@subject = subject
|
7
|
+
end
|
8
|
+
|
9
|
+
def to(*args)
|
10
|
+
return @to if args.empty?
|
11
|
+
@to = args.first
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
def from(*args)
|
16
|
+
return @from if args.empty?
|
17
|
+
@from = args.first
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def with(attributes)
|
22
|
+
@attributes = attributes
|
23
|
+
self
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'timeout'
|
2
|
+
|
3
|
+
module MailChecker
|
4
|
+
class ExpectationMatcher
|
5
|
+
def matches?(expectation)
|
6
|
+
attributes = {}
|
7
|
+
attributes['subject'] = expectation.subject if expectation.subject
|
8
|
+
attributes['sender'] = expectation.from if expectation.from
|
9
|
+
attributes['recipients'] = expectation.to if expectation.to
|
10
|
+
attributes.reverse_merge!(expectation.attributes) if expectation.attributes
|
11
|
+
|
12
|
+
@attributes = attributes
|
13
|
+
|
14
|
+
begin
|
15
|
+
Timeout::timeout(5) do
|
16
|
+
loop do
|
17
|
+
break if MailChecker::Mail.any? do |mail|
|
18
|
+
attributes.all? { |a, v| attribute_matches?([*mail.attributes[a]], to_regexp([*v])) }
|
19
|
+
end
|
20
|
+
|
21
|
+
sleep 0.5
|
22
|
+
end
|
23
|
+
end
|
24
|
+
rescue Timeout::Error
|
25
|
+
false
|
26
|
+
else
|
27
|
+
true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def failure_message
|
32
|
+
"A mail with #{@attributes} was expected to be delivered but was not.\n" +
|
33
|
+
"List of received mails: #{MailChecker::Mail.all.map(&:attributes)}"
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def attribute_matches?(actual, expected)
|
39
|
+
!expected.any? { |e| actual.any? { |a| a !~ e } }
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_regexp(values)
|
43
|
+
values.map { |v| Regexp.new(v) }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module MailChecker
|
2
|
+
class Mail < ActiveResource::Base
|
3
|
+
self.element_name = 'message'
|
4
|
+
|
5
|
+
[:element_path, :new_element_path, :collection_path].each do |method|
|
6
|
+
define_singleton_method method do |*args|
|
7
|
+
super(*args).gsub(/\.#{format.extension}/, '')
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.destroy_all
|
12
|
+
connection.delete(collection_path)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.any?(&block)
|
16
|
+
all.any?(&block)
|
17
|
+
end
|
18
|
+
|
19
|
+
def load(attributes, remove_root = false)
|
20
|
+
super(attributes, remove_root)
|
21
|
+
|
22
|
+
@attributes['sender'].gsub!(/[<>]/, '')
|
23
|
+
@attributes['recipients'].map! { |r| r.gsub(/[<>]/, '') }
|
24
|
+
|
25
|
+
self
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
lib = File.join(File.dirname(__FILE__), 'lib')
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'mail_checker/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = 'mail_checker'
|
7
|
+
gem.version = MailChecker::VERSION
|
8
|
+
gem.authors = ['Eugenio Depalo']
|
9
|
+
gem.email = %w(eugeniodepalo@gmail.com)
|
10
|
+
gem.description = %q{RSpec matchers and helpers to set expectations on mails delivered to MailCatcher}
|
11
|
+
gem.summary = %q{Test mails sent to a MailCatcher SMTP server}
|
12
|
+
gem.homepage = 'https://github.com/responsa/mail_checker'
|
13
|
+
|
14
|
+
gem.add_dependency 'activeresource'
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ['lib']
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mail_checker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Eugenio Depalo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activeresource
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: RSpec matchers and helpers to set expectations on mails delivered to
|
31
|
+
MailCatcher
|
32
|
+
email:
|
33
|
+
- eugeniodepalo@gmail.com
|
34
|
+
executables: []
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- .gitignore
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE.txt
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- lib/mail_checker.rb
|
44
|
+
- lib/mail_checker/configuration.rb
|
45
|
+
- lib/mail_checker/expectation.rb
|
46
|
+
- lib/mail_checker/expectation_matcher.rb
|
47
|
+
- lib/mail_checker/helpers.rb
|
48
|
+
- lib/mail_checker/mail.rb
|
49
|
+
- lib/mail_checker/matchers.rb
|
50
|
+
- lib/mail_checker/version.rb
|
51
|
+
- mail_checker.gemspec
|
52
|
+
homepage: https://github.com/responsa/mail_checker
|
53
|
+
licenses: []
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.8.18
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: Test mails sent to a MailCatcher SMTP server
|
76
|
+
test_files: []
|