Coder Social home page Coder Social logo

rmm5t / minitest-matchers_vaccine Goto Github PK

View Code? Open in Web Editor NEW
35.0 3.0 5.0 30 KB

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

License: MIT License

Ruby 100.00%
minitest minitest-matchers matchers ruby rubygem

minitest-matchers_vaccine's Introduction

Minitest::MatchersVaccine

Gem Version Build Status Maintainability

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.

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("[email protected]", "[email protected]", "[email protected]")
    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("[email protected]", "[email protected]", "[email protected]")
    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

MIT License

minitest-matchers_vaccine's People

Contributors

olleolleolle avatar rmm5t 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

Watchers

 avatar  avatar  avatar

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.