Last Updated: February 25, 2016
·
457
· michaeldupuisjr

Testing: Minitest::Unit

This is the first post regarding test libraries I use with Rails. The goal of this series is to concisely summarize what each library in the testing stack brings to the table.

MiniTest

Provides a suite of testing tools and replaces Test::Unit in Ruby 1.9. It's made up of the following modules:

Minitest::Unit

Unit testing framework using assertions.

class Meme
  def i_can_has_cheezburger?
    "OHAI!"
  end

  def will_it_blend?
    "YES!"
  end
end

Subclass from MiniTest::Test to create your own tests (one per implementation class).

class MemeTest < Mintest::Test
  def setup
    @meme = Meme.new
  end

  def test_that_kitty_can_eat
    assert_equal "OHAI!", @meme.i_can_has_cheezburger?
  end

  def test_that_it_will_not_blend
    refute_match /^no/i, @meme.will_it_blend?
  end
end