Skip to content

Usage with minitest matchers_vaccine

Elliot Winkler edited this page Jun 13, 2019 · 2 revisions

Use the minitest-matchers_vaccine gem to make Minitest understand matchers:

Gemfile:

group :test do
  gem 'shoulda-matchers'
  gem 'minitest-matchers_vaccine'
end

test_helper.rb:

Shoulda::Matchers.configure do |config|
  config.integrate do |with|
    with.test_framework :minitest
    with.library :rails
  end
end

user_test.rb:

class UserTest < Minitest::Test
  def test_validation
    user = User.new
    assert_must validate_presence_of(:email), user
  end
end

or using @subject and must:

class UserTest < Minitest::Test
  def setup
    @subject = User.new
  end

  def test_validation
    must validate_presence_of :email
  end
end