Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/contently/action_mailer_matchers
ActionMailerMatchers provides rspec matchers to test Rails' common ActionMailer functionality.
https://github.com/contently/action_mailer_matchers
actionmailer matcher rails rspec rspec-matchers ruby
Last synced: 2 months ago
JSON representation
ActionMailerMatchers provides rspec matchers to test Rails' common ActionMailer functionality.
- Host: GitHub
- URL: https://github.com/contently/action_mailer_matchers
- Owner: contently
- License: mit
- Created: 2016-08-14T18:03:56.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-11-19T21:53:37.000Z (about 6 years ago)
- Last Synced: 2024-09-25T16:07:12.740Z (3 months ago)
- Topics: actionmailer, matcher, rails, rspec, rspec-matchers, ruby
- Language: Ruby
- Size: 10.7 KB
- Stars: 51
- Watchers: 10
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-rspec - action_mailer_matchers - RSpec matchers to test Rails' common ActionMailer functionality. (Matchers)
README
# ActionMailerMatchers
ActionMailerMatchers provides RSpec matchers to test common ActionMailer functionality.
## Installation
Add this line to your application's Gemfile:
```ruby
group :test do
gem 'action_mailer_matchers', '~> 1.0'
end
```And then execute:
$ bundle install
Or install it yourself as:
$ gem install action_mailer_matchers
Include ActionMailerMatchers in your RSpec config by requiring it and including in your configuration block.
```ruby
require "action_mailer_matchers"...
RSpec.configure do |config|
config.include ActionMailerMatchers
end
```## Usage
ActionMailer allows you to send emails in your Rails application, ActionMailerMatchers provides you with RSpec one-liners that help you to test this functionality.
It is typical to test that an email has been delivered by doing the following:
```ruby
expect { some_action.execute }
.to change { ActionMailer::Base.deliveries.count }.by(1)
```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.
```ruby
expect(some_user).to have_received_email(subject: "My great subject")
expect("[email protected]").to have_received_email(body: "Wonderful email body")
```You can also test that someone has not received an email.
```ruby
expect(some_user).not_to have_received_email
```Emails sent to users using `bcc` or `cc` can be tested using:
```ruby
expect("[email protected]").to have_received_cc_email(body: "Wonderful email body")
expect("[email protected]").to have_received_bcc_email(body: "Wonderful email body")
```## Contributing
1. Fork it ( https://github.com/contently/action_mailer_matchers/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request