Low commit activity in last 3 years
A long-lived project that still receives updates
Rspec macther for ActionMailer
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 0
>= 0

Runtime

 Project Readme

rspec-mailer_matcher

Gem Version Test

An RSpec matcher that asserts a block delivers an ActionMailer message.

Installation

$ bundle add rspec-mailer_matcher --group test

Usage

Require the gem from spec_helper.rb or rails_helper.rb:

require 'rspec-mailer_matcher'

deliver then matches against the mail a block sends:

it 'emails the new user' do
  expect { SignUp.call(email: 'user@example.org') }
    .to deliver to: 'user@example.org', subject: 'Welcome'
end

It works with a subject block too:

subject { proc { SignUp.call(email: 'user@example.org') } }

it { is_expected.to deliver to: 'user@example.org' }

Keys

to, from and subject. to and from match when the address is among the recipients or the senders; subject has to be equal. Any other key raises ArgumentError rather than failing to match, so a typo cannot turn a not_to expectation green.

Every key given has to match the same mail, and the expectation passes when the block delivered at least one such mail.

When it fails, the matcher reports what the block delivered instead:

expected the block to deliver a mail with to: "carol@example.org", but the block delivered:
  to: ["alice@example.org"], from: ["app@example.org"], subject: "Welcome"

Delivery is read from ActionMailer::Base.deliveries, so the block has to deliver during the example. Mail enqueued with deliver_later is not seen unless the job runs inline.

Requirements

Ruby 3.3 or newer, ActionMailer 8.0 or newer. The combinations covered by CI are listed in test.yml.

Development

$ bin/setup            # install dependencies
$ bundle exec rake     # specs and RuboCop
$ bin/console          # IRB with the gem loaded

To run against one ActionMailer series:

$ BUNDLE_GEMFILE=gemfiles/actionmailer_8.0.gemfile bundle exec rake

Releasing

Run the Release workflow and choose a bump. It updates version.rb, tags and pushes, publishes a GitHub release, and pushes the gem to RubyGems.org through trusted publishing.

Contributing

Bug reports and pull requests are welcome at https://github.com/d-mato/rspec-mailer_matcher.

License

Available as open source under the terms of the MIT License.