💉 Adds matcher support to minitest without all the other RSpec-style expectation "infections."
Ruby
Latest commit 2ea5245 Jan 20, 2017 @rmm5t Updated build matrix
Permalink
Failed to load latest commit information.
lib/minitest
test
.gitignore
.travis.yml
CHANGELOG.md Added changelog May 29, 2015
CONTRIBUTING.md
Gemfile
LICENSE.txt Bumped copyright year Jan 20, 2017
README.md Bumped copyright year Jan 20, 2017
Rakefile
minitest-matchers_vaccine.gemspec

README.md

Minitest::MatchersVaccine

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

Installation

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

Usage

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.

Minitest::Test

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

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

  def test_validations
    must have_valid(:email).when("a@a.com", "foo@bar.com", "dave@abc.io")
    wont have_valid(:email).when(nil, "foo", "foo@bar", "@bar.com")
  end

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

Minitest::Spec

describe User do
  subject { User.new }

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

  # Works with valid_attribute
  it "should validate" do
    must have_valid(:email).when("a@a.com", "foo@bar.com", "dave@abc.io")
    wont have_valid(:email).when(nil, "foo", "foo@bar", "@bar.com")
  end

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

Contributing

  1. Fork it ( https://github.com/rmm5t/minitest-matchers_vaccine/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

Credits

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

License

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