Created
May 17, 2013 22:00
-
-
Save masonforest/5602280 to your computer and use it in GitHub Desktop.
rspec matcher for ActionMailer rails email delivery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage | |
# order = create(:order) | |
# | |
# expect { | |
# order.pay! | |
# }.to deliver_email(OrderMailer, :paid, order.id) | |
# | |
# | |
RSpec::Matchers.define :deliver_email do |mailer, action, *args| | |
match do |block| | |
stubbed_mailer = double('mailer', deliver: true) | |
mailer.stub(action => stubbed_mailer) | |
block.call | |
expect(mailer).to have_received(action).with(*args) | |
expect(stubbed_mailer).to have_received(:deliver) | |
end | |
failure_message_for_should do |actual| | |
"expected that block would deliver #{mailer}##{:action}" | |
end | |
failure_message_for_should_not do |actual| | |
"expected that block would not deliver #{mailer}##{:action}" | |
end | |
description do | |
"deliver #{mailer}##{:action}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You've got error in failure messages and description
"#{:action}"
should be"#{action}"