Gem Version Build Status Code Climate

Adds matcher support to minitest without all the other RSpec-style expectation infections.

Using matchers with RSpec-style expectations requires that we infect the objects that we are testing with new methods. Matcher implementations are typically overkill, but there are a lot of good testing libraries that still insist on standardizing on matchers. These matchers still have some value, and this gem tries to extract that value with straight-forward assertions that adhere to the matcher spec.

Why not use minitest-matchers? This gem is actually heavily inspired by and based upon the assertions in minitest-matchers; however, everything else that minitest-matchers brings to the table is unnecessary unless you're bent on a true RSpec-style syntax.

How You Can Help

Square Cash Gratipay Book a Codementor session

If you like this project, buy me a coffee, donate via Gratipay, or book a session with me on Codementor.

Bitcoin: 1rmm5tv6f997JK5bLcGbRCZyVjZUPkQ2m


Add this line to your application's Gemfile:

gem "minitest-matchers_vaccine"

And then execute:

$ bundle

Or install it yourself as:

$ gem install minitest-matchers_vaccine


Includes both assert_must and assert_wont assertions, but also includes must and wont facilitator assertions that automatically default to using the current subject method (aka "let variable") or @subject instance variable.

NOTE: This gem does not allow matchers to be used with an expectation syntax. Let's avoid infecting the objects we're testing.


class UserTest < Minitest::Test
  def setup
    @subject =

  def test_fields_and_associations
    must have_db_column :name
    must belong_to :account
    assert_must have_many(:widgets), @subject

  def test_validations
    must have_valid(:email).when("[email protected]", "[email protected]", "[email protected]")
    wont have_valid(:email).when(nil, "foo", "[email protected]", "")

  # Works with matchers in other libs
  def test_stripping
    assert_must strip_attribute(:name),


describe User do
  subject { }

  # Works with shoulda-matchers
  it "should have fields and associations" do
    must have_db_column :name
    must belong_to :account
    must have_many :widgets

  # Works with valid_attribute
  it "should validate" do
    must have_valid(:email).when("[email protected]", "[email protected]", "[email protected]")
    wont have_valid(:email).when(nil, "foo", "[email protected]", "")

  # Works with matchers in other libs
  it "should strip attributes" do
    must strip_attribute :name


  1. Fork it ( )
  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


The idea was originally inspired by the matcher assertions implementation in minitest-matchers.


Copyright (c) 2014 Ryan McGeary released under the MIT license