GithubHelp home page GithubHelp logo

contently / action_mailer_matchers Goto Github PK

View Code? Open in Web Editor NEW
51.0 10.0 4.0 11 KB

ActionMailerMatchers provides rspec matchers to test Rails' common ActionMailer functionality.

License: MIT License

Ruby 100.00%
rspec rspec-matchers matcher ruby actionmailer rails

action_mailer_matchers's Introduction

ActionMailerMatchers

ActionMailerMatchers provides RSpec matchers to test common ActionMailer functionality.

Installation

Add this line to your application's Gemfile:

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.

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:

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.

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.

expect(some_user).not_to have_received_email

Emails sent to users using bcc or cc can be tested using:

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

action_mailer_matchers's People

Contributors

aaackerman avatar andyklimczak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

action_mailer_matchers's Issues

Gem Load Error is: uninitialized constant RSpec::Matchers

Installed this in a Rails 5 app with Rspec 3.5.3 and get the following when booting the (Puma) server:

Unable to load application: Bundler::GemRequireError: There was an error while trying to load the gem 'action_mailer_matchers'.
Gem Load Error is: uninitialized constant RSpec::Matchers

I think this is due to the Rspec version; I believe a lot has changed around their custom matcher DSL, but I couldn't find anything info in this repo relating to what version of Rspec is supported.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.