mail_assertions 0.1.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 +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +108 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/mail_assertions.rb +2 -0
- data/lib/mail_assertions/asserts.rb +44 -0
- data/lib/mail_assertions/version.rb +3 -0
- data/mail_assertions.gemspec +28 -0
- metadata +126 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 41bfc48b60ca04314ec559fc1b5a1f7cb274c556
|
|
4
|
+
data.tar.gz: 581befd87857b83f3e606e9c5092dd64df6f9457
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d9bd9eae9a53164bec0c446e790d1a1aee03a35237ddf44bbfd5cdc25fa8c2974ad9401a83fb2cc34e107f9c9265fe6176f458f6ceae79193dc1d7e7988730a8
|
|
7
|
+
data.tar.gz: 1024127b7e0e0b4db49e31eca0c96b14e288dcea644d183de048ce7c64bf7a7c3621a4f19dcf89a793ca1dcaaf2b9c2be1af2fb57bf04120f7d4e2a70fd6e4b1
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Magnus Hult
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# MailAssertions
|
|
2
|
+
|
|
3
|
+
This gem provides two new minitest assertions, `assert_mail` and
|
|
4
|
+
`refute_mail` for easily testing whether a specific email has been
|
|
5
|
+
sent by your application.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'mail_assertions'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install mail_assertions
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
You need to include the module `MailAssertions` in
|
|
26
|
+
`ActiveSupport::TestCase`.
|
|
27
|
+
|
|
28
|
+
Also, you almost certainly want to empty the deliveries list between
|
|
29
|
+
every test (otherwise it's hard to know which emails came from this
|
|
30
|
+
test).
|
|
31
|
+
|
|
32
|
+
Therefore, in your `test_helper.rb`:
|
|
33
|
+
|
|
34
|
+
```ruby
|
|
35
|
+
class ActiveSupport::TestCase
|
|
36
|
+
include MailAssertions
|
|
37
|
+
|
|
38
|
+
def setup
|
|
39
|
+
ActionMailer::Base.deliveries.clear
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### `assert_mail(conditions, &block)`
|
|
45
|
+
|
|
46
|
+
Conditions is a hash of attributes on the message object and the
|
|
47
|
+
value you're looking for.
|
|
48
|
+
|
|
49
|
+
```ruby
|
|
50
|
+
# Fails unless there was exactly email sent with the subject
|
|
51
|
+
# Hello World
|
|
52
|
+
assert_mail subject: 'Hello World'
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
You can also specify several conditions, in which case all must apply
|
|
56
|
+
for the email to match:
|
|
57
|
+
|
|
58
|
+
```ruby
|
|
59
|
+
# Fails unless there was exactly one email with the subject Hello World
|
|
60
|
+
# sent to hello@example.com.
|
|
61
|
+
assert_mail subject: 'Hello World', to: ['hello@example.com']
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Optionally, the values may be regular expressions in which case the
|
|
65
|
+
email's value will need to match it
|
|
66
|
+
|
|
67
|
+
```ruby
|
|
68
|
+
# Fails unless there was exactly one email with a subject starting
|
|
69
|
+
# with an A
|
|
70
|
+
assert_mail subject: /^A/
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The optional block is invoked with the matching mail
|
|
74
|
+
|
|
75
|
+
```ruby
|
|
76
|
+
assert_mail subject: 'Hello World' do |mail|
|
|
77
|
+
# Further assertions about the email here
|
|
78
|
+
end
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
As a convenience, if the block accepts two arguments, the second
|
|
82
|
+
will be the HTML body of the email (`mail.html_part.body.to_s`)
|
|
83
|
+
|
|
84
|
+
```ruby
|
|
85
|
+
assert_mail subject: 'Hello World' do |mail, html|
|
|
86
|
+
# Further assertions about the email or its html here
|
|
87
|
+
end
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### `refute_mail(conditions)`
|
|
91
|
+
|
|
92
|
+
Works similarly to `assert_mail` but fails unless no emails matching
|
|
93
|
+
the conditions have been sent.
|
|
94
|
+
|
|
95
|
+
## Development
|
|
96
|
+
|
|
97
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
98
|
+
|
|
99
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
100
|
+
|
|
101
|
+
## Contributing
|
|
102
|
+
|
|
103
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/hult/mail_assertions.
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
## License
|
|
107
|
+
|
|
108
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "mail_assertions"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require 'action_mailer'
|
|
2
|
+
require 'active_support'
|
|
3
|
+
|
|
4
|
+
module MailAssertions
|
|
5
|
+
def assert_mail(conditions = {}, &block)
|
|
6
|
+
emails = list_with_conditions(ActionMailer::Base.deliveries, conditions)
|
|
7
|
+
unless emails.count == 1
|
|
8
|
+
all_subjects = ActionMailer::Base.deliveries.map(&:subject)
|
|
9
|
+
if emails.count == 0
|
|
10
|
+
assert false, "The mail '#{conditions}' was not sent: <#{all_subjects.join(', ')}>"
|
|
11
|
+
else
|
|
12
|
+
assert false, "More than one mail '#{conditions}' was sent: <#{all_subjects.join(', ')}>"
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
mail = emails.first
|
|
16
|
+
if block_given?
|
|
17
|
+
case block.arity
|
|
18
|
+
when 2
|
|
19
|
+
yield mail, mail.html_part.body.to_s
|
|
20
|
+
else
|
|
21
|
+
yield mail
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def refute_mail(conditions = {})
|
|
27
|
+
assert_empty list_with_conditions(ActionMailer::Base.deliveries, conditions)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def list_with_conditions(list, conditions)
|
|
33
|
+
raise ArgumentError.new("specify at least one condition") if conditions.blank?
|
|
34
|
+
list.select do |item|
|
|
35
|
+
conditions.map do |name, value|
|
|
36
|
+
if value.kind_of? Regexp
|
|
37
|
+
item.send(name) =~ value
|
|
38
|
+
else
|
|
39
|
+
item.send(name) == value
|
|
40
|
+
end
|
|
41
|
+
end.all?
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'mail_assertions/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "mail_assertions"
|
|
8
|
+
spec.version = MailAssertions::VERSION
|
|
9
|
+
spec.authors = ["Magnus Hult"]
|
|
10
|
+
spec.email = ["magnus@magnushult.se"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{Minitest asserts for checking that specific emails were (or were not) sent.}
|
|
13
|
+
spec.homepage = "https://github.com/hult/mail_assertions"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
|
18
|
+
end
|
|
19
|
+
spec.bindir = "exe"
|
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
21
|
+
spec.require_paths = ["lib"]
|
|
22
|
+
|
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
25
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
|
26
|
+
spec.add_development_dependency "active_support", "~> 5.0"
|
|
27
|
+
spec.add_development_dependency "action_mailer", "~> 5.0"
|
|
28
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: mail_assertions
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Magnus Hult
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-03-23 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.14'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.14'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: minitest
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '5.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '5.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: active_support
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '5.0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '5.0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: action_mailer
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '5.0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '5.0'
|
|
83
|
+
description:
|
|
84
|
+
email:
|
|
85
|
+
- magnus@magnushult.se
|
|
86
|
+
executables: []
|
|
87
|
+
extensions: []
|
|
88
|
+
extra_rdoc_files: []
|
|
89
|
+
files:
|
|
90
|
+
- ".gitignore"
|
|
91
|
+
- ".travis.yml"
|
|
92
|
+
- Gemfile
|
|
93
|
+
- LICENSE.txt
|
|
94
|
+
- README.md
|
|
95
|
+
- Rakefile
|
|
96
|
+
- bin/console
|
|
97
|
+
- bin/setup
|
|
98
|
+
- lib/mail_assertions.rb
|
|
99
|
+
- lib/mail_assertions/asserts.rb
|
|
100
|
+
- lib/mail_assertions/version.rb
|
|
101
|
+
- mail_assertions.gemspec
|
|
102
|
+
homepage: https://github.com/hult/mail_assertions
|
|
103
|
+
licenses:
|
|
104
|
+
- MIT
|
|
105
|
+
metadata: {}
|
|
106
|
+
post_install_message:
|
|
107
|
+
rdoc_options: []
|
|
108
|
+
require_paths:
|
|
109
|
+
- lib
|
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
|
+
requirements:
|
|
112
|
+
- - ">="
|
|
113
|
+
- !ruby/object:Gem::Version
|
|
114
|
+
version: '0'
|
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
|
+
requirements:
|
|
117
|
+
- - ">="
|
|
118
|
+
- !ruby/object:Gem::Version
|
|
119
|
+
version: '0'
|
|
120
|
+
requirements: []
|
|
121
|
+
rubyforge_project:
|
|
122
|
+
rubygems_version: 2.5.1
|
|
123
|
+
signing_key:
|
|
124
|
+
specification_version: 4
|
|
125
|
+
summary: Minitest asserts for checking that specific emails were (or were not) sent.
|
|
126
|
+
test_files: []
|