action_mailer_matchers 1.0.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CONTRIBUTING.md +91 -0
- data/LICENSE.txt +1 -1
- data/README.md +49 -5
- data/action_mailer_matchers.gemspec +1 -1
- data/lib/action_mailer_matchers.rb +38 -22
- data/lib/action_mailer_matchers/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3ea0ac17a513073551406e4ad8b1377070f6bfda1ee4fe423b1e11a577dd1b06
|
4
|
+
data.tar.gz: b75e043109da0dbaf5fd6925893c35a045e237a41561cdfb5f1af7a3075f3293
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36fa17b7ee1d1d9261892d5c947f3d630b4a6e4f83a9b9a32388e46ba7132b13844e1aac9e42d908be95b2d72cf1cd4bb2ee37060dac998b9327c72f5adcb8e6
|
7
|
+
data.tar.gz: 394b847a27d9f9c0dd8e79dc7ccbeb22519611a0acbfcd733e84bb644df253ffa1d67b4c2cefc2be7c4f3b441600664bb9c1d39855357f926fb26176c39bb68d
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
When contributing to this repository, please first discuss the change you wish to make by creating an issue.
|
4
|
+
|
5
|
+
Please note we have a code of conduct, please follow it in all your interactions with the project.
|
6
|
+
|
7
|
+
## Pull Request Process
|
8
|
+
|
9
|
+
1. Ensure any install or build dependencies are removed before the end of the layer when doing a
|
10
|
+
build.
|
11
|
+
2. Update the README.md with details of changes to the interface, this includes new environment
|
12
|
+
variables, exposed ports, useful file locations and container parameters.
|
13
|
+
3. Increase the version numbers in any examples files and the README.md to the new version that this
|
14
|
+
Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/).
|
15
|
+
4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you
|
16
|
+
do not have permission to do that, you may request the second reviewer to merge it for you.
|
17
|
+
|
18
|
+
## Code of Conduct
|
19
|
+
|
20
|
+
### Our Pledge
|
21
|
+
|
22
|
+
In the interest of fostering an open and welcoming environment, we as
|
23
|
+
contributors and maintainers pledge to making participation in our project and
|
24
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
25
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
26
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
27
|
+
orientation.
|
28
|
+
|
29
|
+
### Our Standards
|
30
|
+
|
31
|
+
Examples of behavior that contributes to creating a positive environment
|
32
|
+
include:
|
33
|
+
|
34
|
+
- Using welcoming and inclusive language
|
35
|
+
- Being respectful of differing viewpoints and experiences
|
36
|
+
- Gracefully accepting constructive criticism
|
37
|
+
- Focusing on what is best for the community
|
38
|
+
- Showing empathy towards other community members
|
39
|
+
|
40
|
+
Examples of unacceptable behavior by participants include:
|
41
|
+
|
42
|
+
- The use of sexualized language or imagery and unwelcome sexual attention or
|
43
|
+
advances
|
44
|
+
- Trolling, insulting/derogatory comments, and personal or political attacks
|
45
|
+
- Public or private harassment
|
46
|
+
- Publishing others' private information, such as a physical or electronic
|
47
|
+
address, without explicit permission
|
48
|
+
- Other conduct which could reasonably be considered inappropriate in a
|
49
|
+
professional setting
|
50
|
+
|
51
|
+
### Our Responsibilities
|
52
|
+
|
53
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
54
|
+
behavior and are expected to take appropriate and fair corrective action in
|
55
|
+
response to any instances of unacceptable behavior.
|
56
|
+
|
57
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
58
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
59
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
60
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
61
|
+
threatening, offensive, or harmful.
|
62
|
+
|
63
|
+
### Scope
|
64
|
+
|
65
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
66
|
+
when an individual is representing the project or its community. Examples of
|
67
|
+
representing a project or community include using an official project e-mail
|
68
|
+
address, posting via an official social media account, or acting as an appointed
|
69
|
+
representative at an online or offline event. Representation of a project may be
|
70
|
+
further defined and clarified by project maintainers.
|
71
|
+
|
72
|
+
### Enforcement
|
73
|
+
|
74
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
75
|
+
reported by contacting the project team at devops@contently.com. All
|
76
|
+
complaints will be reviewed and investigated and will result in a response that
|
77
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
78
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
79
|
+
Further details of specific enforcement policies may be posted separately.
|
80
|
+
|
81
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
82
|
+
faith may face temporary or permanent repercussions as determined by other
|
83
|
+
members of the project's leadership.
|
84
|
+
|
85
|
+
### Attribution
|
86
|
+
|
87
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
88
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
89
|
+
|
90
|
+
[homepage]: http://contributor-covenant.org
|
91
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,28 +1,72 @@
|
|
1
1
|
# ActionMailerMatchers
|
2
2
|
|
3
|
-
|
3
|
+
ActionMailerMatchers provides RSpec matchers to test common ActionMailer functionality.
|
4
|
+
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
7
8
|
Add this line to your application's Gemfile:
|
8
9
|
|
9
|
-
|
10
|
+
```ruby
|
11
|
+
group :test do
|
12
|
+
gem 'action_mailer_matchers', '~> 1.0'
|
13
|
+
end
|
14
|
+
```
|
10
15
|
|
11
16
|
And then execute:
|
12
17
|
|
13
|
-
$ bundle
|
18
|
+
$ bundle install
|
14
19
|
|
15
20
|
Or install it yourself as:
|
16
21
|
|
17
22
|
$ gem install action_mailer_matchers
|
18
23
|
|
24
|
+
Include ActionMailerMatchers in your RSpec config by requiring it and including in your configuration block.
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
require "action_mailer_matchers"
|
28
|
+
|
29
|
+
...
|
30
|
+
|
31
|
+
RSpec.configure do |config|
|
32
|
+
config.include ActionMailerMatchers
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
19
36
|
## Usage
|
20
37
|
|
21
|
-
|
38
|
+
ActionMailer allows you to send emails in your Rails application, ActionMailerMatchers provides you with RSpec one-liners that help you to test this functionality.
|
39
|
+
|
40
|
+
It is typical to test that an email has been delivered by doing the following:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
expect { some_action.execute }
|
44
|
+
.to change { ActionMailer::Base.deliveries.count }.by(1)
|
45
|
+
```
|
46
|
+
|
47
|
+
However, this does not specify what email was sent and to where. ActionMailerMatchers solves this problem by providing the `have_received_email` matcher, which ensures that the passed email address or user (which must respond `.email`) was the email's "to" address. You may also use the optional subject and body arguments to check that content matches the email you were expecting to send.
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
expect(some_user).to have_received_email(subject: "My great subject")
|
51
|
+
expect("address@email.com").to have_received_email(body: "Wonderful email body")
|
52
|
+
```
|
53
|
+
|
54
|
+
You can also test that someone has not received an email.
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
expect(some_user).not_to have_received_email
|
58
|
+
```
|
59
|
+
|
60
|
+
Emails sent to users using `bcc` or `cc` can be tested using:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
expect("cc@email.com").to have_received_cc_email(body: "Wonderful email body")
|
64
|
+
expect("bcc@email.com").to have_received_bcc_email(body: "Wonderful email body")
|
65
|
+
```
|
22
66
|
|
23
67
|
## Contributing
|
24
68
|
|
25
|
-
1. Fork it ( https://github.com/
|
69
|
+
1. Fork it ( https://github.com/contently/action_mailer_matchers/fork )
|
26
70
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
71
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
72
|
4. Push to the branch (`git push origin my-new-feature`)
|
@@ -6,7 +6,7 @@ require 'action_mailer_matchers/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "action_mailer_matchers"
|
8
8
|
spec.version = ActionMailerMatchers::VERSION
|
9
|
-
spec.authors = ["Alexandra Ackerman, Kevin Curtin"]
|
9
|
+
spec.authors = ["Alexandra Ackerman, Kevin Curtin, Andy Klimczak"]
|
10
10
|
spec.email = ["aaackerman.dev@gmail.com"]
|
11
11
|
spec.summary = %q{ActionMailerMatchers provides rspec matchers to test Rails' common ActionMailer functionality.}
|
12
12
|
spec.description = %q{ActionMailerMatchers provides rspec matchers to test Rails' common ActionMailer functionality.}
|
@@ -5,36 +5,52 @@ module ActionMailerMatchers
|
|
5
5
|
|
6
6
|
matcher :have_received_email do |email_or_user|
|
7
7
|
match do |email_or_user|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
body = expected_attrs[:body]
|
8
|
+
received_email?(email_or_user, expected)
|
9
|
+
end
|
10
|
+
end
|
12
11
|
|
13
|
-
|
12
|
+
matcher :have_received_cc_email do |email_or_user|
|
13
|
+
match do |email_or_user|
|
14
|
+
received_email?(email_or_user, expected, :cc)
|
15
|
+
end
|
16
|
+
end
|
14
17
|
|
15
|
-
|
18
|
+
matcher :have_received_bcc_email do |email_or_user|
|
19
|
+
match do |email_or_user|
|
20
|
+
received_email?(email_or_user, expected, :bcc)
|
16
21
|
end
|
22
|
+
end
|
17
23
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
24
|
+
def received_email?(email_or_user, expected, email_method = :to)
|
25
|
+
expected_attrs = expected.present? ? expected : {}
|
26
|
+
email = email_or_user.try(:email) || email_or_user
|
27
|
+
email_subject = expected_attrs[:subject]
|
28
|
+
body = expected_attrs[:body]
|
23
29
|
|
24
|
-
|
25
|
-
|
26
|
-
|
30
|
+
matching_email = matching_mail_for(email, body, email_subject, email_method)
|
31
|
+
|
32
|
+
expect(matching_email.present?).to eql(true)
|
33
|
+
end
|
34
|
+
|
35
|
+
def matching_mail_for(email, body, email_subject, email_method)
|
36
|
+
deliveries.detect do |mail|
|
37
|
+
has_expected_email = mail.send(email_method).include?(email)
|
38
|
+
has_expected_body = body ? body_for(mail).include?(body) : true
|
39
|
+
has_expected_subject = email_subject ? mail.subject.include?(email_subject) : true
|
27
40
|
|
28
|
-
|
29
|
-
if mail.try(:parts).present?
|
30
|
-
mail.try(:parts).try(:first).try(:body).try(:raw_source)
|
31
|
-
else
|
32
|
-
mail.try(:body).try(:raw_source)
|
33
|
-
end
|
41
|
+
has_expected_email && has_expected_body && has_expected_subject
|
34
42
|
end
|
43
|
+
end
|
35
44
|
|
36
|
-
|
37
|
-
|
45
|
+
def body_for(mail)
|
46
|
+
if mail.try(:parts).present?
|
47
|
+
mail.try(:parts).try(:first).try(:body).try(:raw_source)
|
48
|
+
else
|
49
|
+
mail.try(:body).try(:raw_source)
|
38
50
|
end
|
39
51
|
end
|
52
|
+
|
53
|
+
def deliveries
|
54
|
+
ActionMailer::Base.deliveries
|
55
|
+
end
|
40
56
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_mailer_matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Alexandra Ackerman, Kevin Curtin
|
7
|
+
- Alexandra Ackerman, Kevin Curtin, Andy Klimczak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -47,6 +47,7 @@ extensions: []
|
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
49
|
- ".gitignore"
|
50
|
+
- CONTRIBUTING.md
|
50
51
|
- Gemfile
|
51
52
|
- LICENSE.txt
|
52
53
|
- README.md
|
@@ -74,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
75
|
version: '0'
|
75
76
|
requirements: []
|
76
77
|
rubyforge_project:
|
77
|
-
rubygems_version: 2.
|
78
|
+
rubygems_version: 2.7.6
|
78
79
|
signing_key:
|
79
80
|
specification_version: 4
|
80
81
|
summary: ActionMailerMatchers provides rspec matchers to test Rails' common ActionMailer
|