arzumy md short notes on small discoveries

How To Test ActionMailer With RSpec And shoulda-matchers

27 September 2013

Today I upgraded shoulda-matchers gem from version 1.4.2 to 2.4.0. shoulda-matchers is a bunch of one-liners to test Rails functionality and compatible with RSpec. My spec suite broken after the upgrade. This post is a walkthrough about the changes I had to make to fix my spec suite.

In version 1.4.2, I added these lines in spec/spec_helper.rb.

  require 'shoulda-matchers'
  include Shoulda::Matchers::ActionMailer

After upgrade, I got this error:

  uninitialized constant Shoulda::Matchers::ActionMailer (NameError)

A quick peek at the source shows the error is right (because your know, error messages could lie to you), ActionMailer matchers not included in shoulda-matchers anymore. I can have the same functionalities in Mail itself. Read more from Using Mail with Testing or Spec’ing Libraries.

Now, I just need to replace include Shoulda::Matchers::ActionMailer with include Mail::Matchers. Because the matchers directly copied from shoulda-matchers, no further change needed.

arzumy md, CTO at Fave and BillPlz.

https://www.facebook.com/arzumy
https://my.linkedin.com/in/arzumy
https://www.google.com/search?q=arzumy